Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Fixes issues by multiple file renames #1656 (#1658)

Stanimir1eeaa2c2a7b4
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 5defe391a..4de599698 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -1554,9 +1554,9 @@ export const actions = {
}),
showNotification: (
text: string,
- notificationType: string = 'default',
- autohide: boolean = true,
- tid: string = 'notificationTID'
+ notificationType = 'default',
+ autohide = true,
+ tid = 'notificationTID'
) => ({
type: types.SET_NOTIFICATION,
visible: true,
@@ -1849,7 +1849,7 @@ export const actions = {
reflectUpdateSidecarTags: (
path: string,
tags: Array<TS.Tag>,
- updateIndex: boolean = true
+ updateIndex = true
) => (dispatch: (actions: Object) => void, getState: () => any) => {
const { openedFiles, selectedEntries } = getState().app;
/**
@@ -1914,8 +1914,8 @@ export const actions = {
});
},
renameFile: (filePath: string, newFilePath: string) => (
- dispatch: (actions: Object) => void
- ) =>
+ dispatch: (action) => void
+ ): Promise<boolean> =>
PlatformIO.renameFilePromise(filePath, newFilePath)
.then(result => {
const newFilePathFromPromise = result[1];
@@ -1968,6 +1968,7 @@ export const actions = {
' with ' +
err
);
+ return false;
});
return true;
})
@@ -1980,7 +1981,8 @@ export const actions = {
true
)
);
- throw error;
+ return false;
+ // throw error;
}),
openFileNatively: (selectedFile?: string) => (
dispatch: (actions: Object) => void,
@@ -2145,7 +2147,7 @@ export const actions = {
console.log('Not supported URL format: ' + decodedURI);
}
},
- openURLExternally: (url: string, skipConfirmation: boolean = false) => () => {
+ openURLExternally: (url: string, skipConfirmation = false) => () => {
if (skipConfirmation) {
PlatformIO.openUrl(url);
} else if (
diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.ts
index 4ab590089..b94d67bc0 100644
--- a/app/reducers/tagging-actions.ts
+++ b/app/reducers/tagging-actions.ts
@@ -55,11 +55,10 @@ const persistTagsInSidecarFile = state => {
};
const actions = {
- addTags: (
- paths: Array<string>,
- tags: Array<TS.Tag>,
- updateIndex: boolean = true
- ) => (dispatch: (actions: Object) => void, getState: () => any) => {
+ addTags: (paths: Array<string>, tags: Array<TS.Tag>, updateIndex = true) => (
+ dispatch: (action) => void,
+ getState: () => any
+ ) => {
const { settings, taglibrary } = getState();
let defaultTagLocation;
if (settings.geoTaggingFormat.toLowerCase() === 'mgrs') {
@@ -163,7 +162,7 @@ const actions = {
addTagsToEntry: (
path: string,
tags: Array<TS.Tag>,
- updateIndex: boolean = true
+ updateIndex = true
) => async (dispatch: (actions: Object) => void, getState: () => any) => {
const { settings } = getState();
const entryProperties = await PlatformIO.getPropertiesPromise(path);
@@ -630,26 +629,62 @@ const actions = {
}
}
},
- removeAllTags: (paths: Array<string>) => (
- dispatch: (actions: Object) => void
+ removeAllTags: (paths: Array<string>) => async (
+ dispatch: (action) => Promise<boolean>
) => {
- paths.map(path => {
- dispatch(actions.removeAllTagsFromEntry(path));
- return true;
- });
+ for (const path of paths) {
+ // eslint-disable-next-line no-await-in-loop
+ const resultMeta = await dispatch(
+ actions.removeAllTagsFromMetaData(path)
+ );
+ // eslint-disable-next-line no-await-in-loop
+ const resultName = await dispatch(
+ actions.removeAllTagsFromFilename(path)
+ );
+ }
},
- removeAllTagsFromEntry: (path: string) => (
- dispatch: (actions: Object) => void,
+ removeAllTagsFromFilename: (path: string) => (
+ dispatch: (action) => Promise<boolean>,
getState: () => any
- ) => {
+ ): Promise<boolean> => {
const { settings } = getState();
+ // Tags in file name case, check is file
+ const extractedTags = extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
+ if (extractedTags.length > 0) {
+ const fileTitle = extractTitle(path, false, PlatformIO.getDirSeparator());
+ let fileExt = extractFileExtension(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
+ if (fileExt.length > 0) {
+ fileExt = '.' + fileExt;
+ }
+ const newFilePath =
+ (containingDirectoryPath
+ ? containingDirectoryPath + PlatformIO.getDirSeparator()
+ : '') +
+ fileTitle +
+ fileExt;
+ return dispatch(AppActions.renameFile(path, newFilePath));
+ }
+ return Promise.resolve(true);
+ },
+ removeAllTagsFromMetaData: (path: string) => (
+ dispatch: (action) => void,
+ getState: () => any
+ ): Promise<boolean> =>
loadMetaDataPromise(path)
.then(fsEntryMeta => {
const updatedFsEntryMeta = {
...fsEntryMeta,
tags: []
};
- saveMetaDataPromise(path, updatedFsEntryMeta)
+ return saveMetaDataPromise(path, updatedFsEntryMeta)
.then(() => {
// TODO rethink this updateCurrentDirEntry and not need for KanBan
dispatch(AppActions.reflectUpdateSidecarTags(path, []));
@@ -657,7 +692,6 @@ const actions = {
if (openedFiles.find(obj => obj.path === path)) {
dispatch(AppActions.updateOpenedFile(path, { tags: [] }));
}
- removeAllTagsFromFilename();
return true;
})
.catch(err => {
@@ -671,47 +705,14 @@ const actions = {
true
)
);
- removeAllTagsFromFilename();
+ return false;
});
- return true;
})
.catch(error => {
console.warn('Could not find meta file for ' + path + ' with ' + error);
// dispatch(AppActions.showNotification('Adding tags failed', 'error', true));
- removeAllTagsFromFilename();
- });
-
- function removeAllTagsFromFilename() {
- // Tags in file name case, check is file
- const extractedTags = extractTags(
- path,
- settings.tagDelimiter,
- PlatformIO.getDirSeparator()
- );
- if (extractedTags.length > 0) {
- const fileTitle = extractTitle(
- path,
- false,
- PlatformIO.getDirSeparator()
- );
- let fileExt = extractFileExtension(path, PlatformIO.getDirSeparator());
- const containingDirectoryPath = extractContainingDirectoryPath(
- path,
- PlatformIO.getDirSeparator()
- );
- if (fileExt.length > 0) {
- fileExt = '.' + fileExt;
- }
- const newFilePath =
- (containingDirectoryPath
- ? containingDirectoryPath + PlatformIO.getDirSeparator()
- : '') +
- fileTitle +
- fileExt;
- dispatch(AppActions.renameFile(path, newFilePath));
- }
- }
- },
+ return false;
+ }),
// smart tagging -> PRO
addDateTag: (paths: Array<string>) => () =>
// dispatch: (actions: Object) => void
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 489681eaa..1ac0c826b 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -391,7 +391,7 @@ export function findExtensionPathForId(extensionId: string): string {
export function findExtensionsForEntry(
supportedFileTypes: Array<any>,
entryPath: string,
- isFile: boolean = true
+ isFile = true
): OpenedEntry {
const fileExtension = extractFileExtension(
entryPath,
@@ -534,7 +534,7 @@ function persistIndex(param: string | any, directoryIndex: any) {
export function createDirectoryIndex(
param: string | any,
- extractText: boolean = false,
+ extractText = false,
ignorePatterns: Array<string> = [],
enableWS = true
// disableIndexing = true,
@@ -759,13 +759,18 @@ export function deleteFilesPromise(filePathList: Array<string>) {
}
export function renameFilesPromise(renameJobs: Array<Array<string>>) {
- const fileRenamePromises = [];
+ return Promise.all(
+ renameJobs.map(renameJob =>
+ PlatformIO.renameFilePromise(renameJob[0], renameJob[1])
+ )
+ );
+ /* const fileRenamePromises = [];
renameJobs.forEach(renameJob => {
fileRenamePromises.push(
PlatformIO.renameFilePromise(renameJob[0], renameJob[1])
);
});
- return Promise.all(fileRenamePromises);
+ return Promise.all(fileRenamePromises); */
}
export function copyFilesPromise(copyJobs: Array<Array<string>>) {
@@ -776,10 +781,7 @@ export function copyFilesPromise(copyJobs: Array<Array<string>>) {
return Promise.all(ioJobPromises);
}
-export async function loadSubFolders(
- path: string,
- loadHidden: boolean = false
-) {
+export async function loadSubFolders(path: string, loadHidden = false) {
const folderContent = await PlatformIO.listDirectoryPromise(path, []); // 'extractThumbPath']);
const subfolders = [];
let i = 0;