Skip to content

Commit

Permalink
fix: cut not working accross device
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlimjustin committed Nov 21, 2021
1 parent 78ba08b commit 4575baa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
17 changes: 11 additions & 6 deletions src/Api/operation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
copyFile,
renameFile,
removeDir,
removeFile,
} from '@tauri-apps/api/fs';
import { copyFile, renameFile, removeDir, removeFile } from '@tauri-apps/api/fs';
import DirectoryAPI from './directory';
/**
* Invoke Rust command to operate files/dirs
Expand All @@ -30,6 +25,16 @@ class OperationAPI {
return await renameFile(this.src, this.dest);
}

async cut(): Promise<void> {
await this.copyFile();
await this.unlink();
return;
}

/**
* Unlink files/dirs
* @returns {Promise<void>}
*/
async unlink(): Promise<void> {
if (await new DirectoryAPI(this.src).isDir()) {
return await removeDir(this.src, { recursive: true });
Expand Down
21 changes: 4 additions & 17 deletions src/Components/Files/File Operation/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,17 @@ const cpy = async (src: string, dest: string) => {
dest += ' - COPY';
}
if (await new FileAPI(dest).exists()) {
if (
!(await ConfirmDialog(
'Target file exists',
'Target directory with the same file name exists, do you want to overwrite it?',
'No'
))
)
if (!(await ConfirmDialog('Target file exists', 'Target directory with the same file name exists, do you want to overwrite it?', 'No')))
return;
}
new OperationAPI(src, dest).copyFile();
};
const Paste = async (target: string): Promise<void> => {
const clipboard = await Storage.get('clipboard');

const recuriveCopy = async (
_path: string,
_target: string,
firstRecursion = false
) => {
const recuriveCopy = async (_path: string, _target: string, firstRecursion = false) => {
let useCopySuffix = false;
if (
firstRecursion &&
normalizeSlash(getDirname(_path)) === normalizeSlash(_target)
) {
if (firstRecursion && normalizeSlash(getDirname(_path)) === normalizeSlash(_target)) {
useCopySuffix = true;
}
const subdirInfo = new DirectoryAPI(normalizeSlash(_path));
Expand Down Expand Up @@ -78,7 +65,7 @@ const Paste = async (target: string): Promise<void> => {
await new OperationAPI(dest).unlink();
}
}
await new OperationAPI(file, dest).rename();
await new OperationAPI(file, dest).cut();
break;
}
}
Expand Down

1 comment on commit 4575baa

@vercel
Copy link

@vercel vercel bot commented on 4575baa Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.