Skip to content

Commit af9555c

Browse files
committed
feat: if that file is already in wikiFolderLocation / wikiFolderToMove , then don't need to move the file
1 parent 67d50ef commit af9555c

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/tidgi-external-attachments/handleImportingFile.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ export function handleImportingFile(info: ImportFileInfo, wikiFolderLocation: st
4444
'',
4545
);
4646
const willMoveFromPath = filePath;
47-
const willMoveToPath = joinPaths(
48-
wikiFolderLocation,
49-
wikiFolderToMove,
50-
basePath(filePath),
51-
);
52-
filePath = willMoveToPath;
53-
moveFileMetaData = { willMoveToPath, willMoveFromPath };
47+
const targetFolder = joinPaths(wikiFolderLocation, wikiFolderToMove);
48+
const willMoveToPath = joinPaths(targetFolder, basePath(filePath));
49+
50+
// Check if the file is already in the target location - if so, don't move it
51+
// This prevents unnecessary file operations
52+
const isAlreadyInTargetLocation = filePath.startsWith(targetFolder);
53+
54+
if (!isAlreadyInTargetLocation) {
55+
// Only set up the move operation if the file isn't already where it needs to be
56+
moveFileMetaData = { willMoveToPath, willMoveFromPath };
57+
filePath = willMoveToPath; // Update filepath to the eventual destination
58+
}
59+
// If file is already in target location, keep using original filePath
5460
}
5561

5662
// Read configuration for path handling

0 commit comments

Comments
 (0)