Skip to content

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

fix-1000files-move (#1941)

Stanimir8cd391a3d11c
diff --git a/.gitignore b/.gitignore
index df81f55fe..7baed8370 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,6 +102,7 @@ tests/*
!tests/global-teardown-web.js
!tests/setup-functions.js
!tests/test-data-refresh.js
+!tests/create-1000files-nothumbs.sh
builds/*
web/sw-con
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 826a90de5..6c5636ca7 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -47,7 +47,6 @@ import {
OpenedEntry,
getSelectedEntries,
getProgress,
- getEditedEntryPaths,
isSearchMode,
getLastSearchTimestamp
} from '../reducers/app';
@@ -213,7 +212,7 @@ interface Props {
exitSearchMode: () => void;
openURLExternally?: (url: string, skipConfirmation: boolean) => void;
language: string;
- editedEntryPaths: Array<TS.EditedEntryPath>;
+ // editedEntryPaths: Array<TS.EditedEntryPath>;
goBack: () => void;
goForward: () => void;
lastSearchTimestamp: number;
@@ -685,7 +684,7 @@ function mapStateToProps(state) {
progress: getProgress(state),
searchQuery: getSearchQuery(state),
defaultPerspective: getDefaultPerspective(state),
- editedEntryPaths: getEditedEntryPaths(state),
+ //editedEntryPaths: getEditedEntryPaths(state),
currentLocation: getCurrentLocation(state),
lastSearchTimestamp: getLastSearchTimestamp(state),
isSearchMode: isSearchMode(state)
@@ -737,8 +736,7 @@ const areEqual = (prevProp: Props, nextProp: Props) =>
JSON.stringify(nextProp.openedFiles) ===
JSON.stringify(prevProp.openedFiles) &&
JSON.stringify(nextProp.theme) === JSON.stringify(prevProp.theme) &&
- JSON.stringify(nextProp.editedEntryPaths) ===
- JSON.stringify(prevProp.editedEntryPaths) &&
+ // JSON.stringify(nextProp.editedEntryPaths) === JSON.stringify(prevProp.editedEntryPaths) &&
nextProp.windowWidth === prevProp.windowWidth &&
nextProp.windowHeight === prevProp.windowHeight &&
nextProp.language === prevProp.language &&
diff --git a/app/components/dialogs/MoveCopyFilesDialog.tsx b/app/components/dialogs/MoveCopyFilesDialog.tsx
index ad5c0fa36..232adbf8c 100644
--- a/app/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/app/components/dialogs/MoveCopyFilesDialog.tsx
@@ -102,13 +102,22 @@ function MoveCopyFilesDialog(props: Props) {
: [];
useEffect(() => {
- if (selectedDirs.length > 0 && AppConfig.isElectron) {
- // getDirProperties have Electron impl only
+ // getDirProperties have Electron impl only
+ if (
+ selectedDirs.length > 0 &&
+ AppConfig.isElectron &&
+ !PlatformIO.haveObjectStoreSupport() &&
+ !PlatformIO.haveWebDavSupport()
+ ) {
const promises = selectedDirs.map(dirPath => {
- return PlatformIO.getDirProperties(dirPath).then(prop => {
- dirProp.current[dirPath] = prop;
- return true;
- });
+ try {
+ return PlatformIO.getDirProperties(dirPath).then(prop => {
+ dirProp.current[dirPath] = prop;
+ return true;
+ });
+ } catch (ex) {
+ console.debug('getDirProperties:', ex);
+ }
});
Promise.all(promises).then(() => forceUpdate());
}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index d8ff88b69..36d9d6b0f 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -58,7 +58,8 @@ import {
getCleanLocationPath,
updateFsEntries,
loadMetaDataPromise,
- mergeByProp
+ mergeByProp,
+ toFsEntry
} from '-/services/utils-io';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import i18n from '../services/i18n';
@@ -148,8 +149,10 @@ export const types = {
OPEN_HELPFEEDBACK_PANEL: 'APP/OPEN_HELPFEEDBACK_PANEL',
CLOSE_ALLVERTICAL_PANELS: 'APP/CLOSE_ALLVERTICAL_PANELS',
REFLECT_DELETE_ENTRY: 'APP/REFLECT_DELETE_ENTRY',
+ REFLECT_DELETE_ENTRIES: 'APP/REFLECT_DELETE_ENTRIES',
REFLECT_RENAME_ENTRY: 'APP/REFLECT_RENAME_ENTRY',
REFLECT_CREATE_ENTRY: 'APP/REFLECT_CREATE_ENTRY',
+ REFLECT_CREATE_ENTRIES: 'APP/REFLECT_CREATE_ENTRIES',
// REFLECT_UPDATE_SIDECARTAGS: 'APP/REFLECT_UPDATE_SIDECARTAGS',
// REFLECT_UPDATE_SIDECARMETA: 'APP/REFLECT_UPDATE_SIDECARMETA',
UPDATE_CURRENTDIR_ENTRY: 'APP/UPDATE_CURRENTDIR_ENTRY',
@@ -683,6 +686,36 @@ export default (state: any = initialState, action: any) => {
entry => entry.path !== action.path
);
const editedEntryPaths = [{ action: 'delete', path: action.path }];
+ // check if currentDirectoryEntries or openedFiles changed
+ if (
+ state.currentDirectoryEntries.length > newDirectoryEntries.length ||
+ state.openedFiles.length > newOpenedFiles.length
+ ) {
+ return {
+ ...state,
+ editedEntryPaths,
+ currentDirectoryEntries: newDirectoryEntries,
+ openedFiles: newOpenedFiles,
+ isEntryInFullWidth: false
+ };
+ }
+ return {
+ ...state,
+ editedEntryPaths
+ };
+ }
+ case types.REFLECT_DELETE_ENTRIES: {
+ const newDirectoryEntries = state.currentDirectoryEntries.filter(
+ entry => !action.paths.some(path => path === entry.path)
+ );
+ const newOpenedFiles = state.openedFiles.filter(
+ entry => !action.paths.some(path => path === entry.path)
+ );
+ const editedEntryPaths = action.paths.map(path => ({
+ action: 'delete',
+ path: path
+ }));
+ // check if currentDirectoryEntries or openedFiles changed
if (
state.currentDirectoryEntries.length > newDirectoryEntries.length ||
state.openedFiles.length > newOpenedFiles.length
@@ -702,10 +735,14 @@ export default (state: any = initialState, action: any) => {
}
case types.REFLECT_CREATE_ENTRY: {
const newEntry: TS.FileSystemEntry = action.newEntry;
- // Prevent adding entry twice e.g. by the watcher
- const entryIndex = state.currentDirectoryEntries.findIndex(
- entry => entry.path === newEntry.path
- );
+ // Prevent adding entry twice e.g. by entry rename in the watcher
+ if (
+ state.currentDirectoryEntries.some(
+ entry => entry.path === newEntry.path
+ )
+ ) {
+ return state;
+ }
const editedEntryPaths: Array<TS.EditedEntryPath> = [
{
action: newEntry.isFile ? 'createFile' : 'createDir',
@@ -715,12 +752,12 @@ export default (state: any = initialState, action: any) => {
];
// clean all dir separators to have platform independent path match
if (
- entryIndex < 0 &&
+ // entryIndex < 0 &&
extractParentDirectoryPath(
action.newEntry.path,
PlatformIO.getDirSeparator()
).replace(/[/\\]/g, '') ===
- state.currentDirectoryPath.replace(/[/\\]/g, '')
+ state.currentDirectoryPath.replace(/[/\\]/g, '')
) {
return {
...state,
@@ -736,6 +773,33 @@ export default (state: any = initialState, action: any) => {
editedEntryPaths
};
}
+ case types.REFLECT_CREATE_ENTRIES: {
+ if (
+ action.fsEntries.length > 0 &&
+ extractParentDirectoryPath(
+ action.fsEntries[0].path,
+ PlatformIO.getDirSeparator()
+ ).replace(/[/\\]/g, '') ===
+ state.currentDirectoryPath.replace(/[/\\]/g, '')
+ ) {
+ const editedEntryPaths: Array<TS.EditedEntryPath> = action.fsEntries.map(
+ newEntry => ({
+ action: newEntry.isFile ? 'createFile' : 'createDir',
+ path: newEntry.path,
+ uuid: newEntry.uuid
+ })
+ );
+ return {
+ ...state,
+ editedEntryPaths,
+ currentDirectoryEntries: [
+ ...state.currentDirectoryEntries,
+ ...action.fsEntries
+ ]
+ };
+ }
+ return state;
+ }
case types.REFLECT_RENAME_ENTRY: {
const extractedTags = extractTagsAsObjects(
action.newPath,
@@ -2415,37 +2479,36 @@ export const actions = {
type: types.REFLECT_DELETE_ENTRY,
path
}),
+ reflectDeleteEntriesInt: (paths: string[]) => ({
+ type: types.REFLECT_DELETE_ENTRIES,
+ paths
+ }),
reflectDeleteEntry: (path: string) => (dispatch: (action) => void) => {
dispatch(actions.reflectDeleteEntryInt(path));
GlobalSearch.getInstance().reflectDeleteEntry(path);
},
+ reflectDeleteEntries: (paths: string[]) => (dispatch: (action) => void) => {
+ dispatch(actions.reflectDeleteEntriesInt(paths));
+ GlobalSearch.getInstance().reflectDeleteEntries(paths);
+ },
reflectCreateEntryInt: (newEntry: TS.FileSystemEntry) => ({
type: types.REFLECT_CREATE_ENTRY,
newEntry
}),
+ reflectCreateEntriesInt: (fsEntries: Array<TS.FileSystemEntry>) => ({
+ type: types.REFLECT_CREATE_ENTRIES,
+ fsEntries
+ }),
reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => (
dispatch: (action) => void
) => {
- fsEntries.map(entry => dispatch(actions.reflectCreateEntryInt(entry))); // TODO remove map and set state once
+ dispatch(actions.reflectCreateEntriesInt(fsEntries));
dispatch(actions.setSelectedEntries(fsEntries));
},
reflectCreateEntry: (path: string, isFile: boolean) => (
dispatch: (action) => void
) => {
- const newEntry = {
- uuid: getUuid(),
- name: isFile
- ? extractFileName(path, PlatformIO.getDirSeparator())
- : extractDirectoryName(path, PlatformIO.getDirSeparator()),
- isFile,
- extension: extractFileExtension(path, PlatformIO.getDirSeparator()),
- description: '',
- tags: [],
- size: 0,
- lmdt: new Date().getTime(),
- path
- };
- dispatch(actions.reflectCreateEntryObj(newEntry));
+ dispatch(actions.reflectCreateEntryObj(toFsEntry(path, isFile)));
},
reflectCreateEntryObj: (newEntry: TS.FileSystemEntry) => (
dispatch: (action) => void
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index f60a3ce29..48eb40521 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -36,7 +36,8 @@ import {
copyFilesPromise,
getThumbPath,
loadFileMetaDataPromise,
- renameFilesPromise
+ renameFilesPromise,
+ toFsEntry
} from '-/services/utils-io';
import i18n from '../services/i18n';
import { Pro } from '../pro';
@@ -118,11 +119,11 @@ const actions = {
dispatch(
AppActions.showNotification(i18n.t('core:filesMovedSuccessful'))
);
+ // moved files should be added to the index, if the target dir in index
+ dispatch(AppActions.reflectDeleteEntries(paths));
const moveMetaJobs = [];
moveJobs.map(job => {
- dispatch(AppActions.reflectDeleteEntry(job[0])); // moved files should be added to the index, if the target dir in index
-
// Move revisions
loadFileMetaDataPromise(job[0]).then(
(fsEntryMeta: TS.FileSystemEntryMeta) => {
@@ -174,16 +175,16 @@ const actions = {
false
)
]);
- renameFilesPromise(moveMetaJobs)
- .then(() => {
- console.log('Moving meta and thumbs successful');
- return true;
- })
- .catch(err => {
- console.warn('At least one meta or thumb was not moved ' + err);
- });
return true;
});
+ renameFilesPromise(moveMetaJobs)
+ .then(() => {
+ console.log('Moving meta and thumbs successful');
+ return true;
+ })
+ .catch(err => {
+ console.warn('At least one meta or thumb was not moved ' + err);
+ });
return true;
})
.catch(err => {
@@ -225,29 +226,27 @@ const actions = {
copyFiles: (paths: Array<string>, targetPath: string) => (
dispatch: (actions: Object) => void
) => {
- const copyJobs = [];
- paths.map(path => {
- copyJobs.push([
- path,
+ const copyJobs = paths.map(path => {
+ const targetFile =
normalizePath(targetPath) +
- PlatformIO.getDirSeparator() +
- extractFileName(path, PlatformIO.getDirSeparator())
- ]);
- return true;
+ PlatformIO.getDirSeparator() +
+ extractFileName(path, PlatformIO.getDirSeparator());
+ return [path, targetFile];
});
+
+ const targetFiles: string[] = copyJobs.map(job => job[1]);
+
copyFilesPromise(copyJobs)
.then(() => {
dispatch(
AppActions.showNotification(i18n.t('core:filesCopiedSuccessful'))
);
- const copyMetaJobs = [];
- copyJobs.map(job => {
- // dispatch(AppActions.reflectCopyEntry(job[0])); // TODO need only for the index if the target dir is indexed
- copyMetaJobs.push([
+ const copyMetaJobs = copyJobs.flatMap(job => [
+ [
getMetaFileLocationForFile(job[0], PlatformIO.getDirSeparator()),
getMetaFileLocationForFile(job[1], PlatformIO.getDirSeparator())
- ]);
- copyMetaJobs.push([
+ ],
+ [
getThumbFileLocationForFile(
job[0],
PlatformIO.getDirSeparator(),
@@ -258,19 +257,26 @@ const actions = {
PlatformIO.getDirSeparator(),
false
)
- ]);
- copyFilesPromise(copyMetaJobs)
- .then(() => {
- console.log('Copy meta and thumbs successful');
- dispatch(AppActions.reflectCreateEntry(job[1], true));
- return true;
- })
- .catch(err => {
- dispatch(AppActions.reflectCreateEntry(job[1], true));
- console.warn('At least one meta or thumb was not copied ' + err);
- });
- return true;
- });
+ ]
+ ]);
+ copyFilesPromise(copyMetaJobs)
+ .then(() => {
+ console.log('Copy meta and thumbs successful');
+ dispatch(
+ AppActions.reflectCreateEntries(
+ targetFiles.map(filePath => toFsEntry(filePath, true))
+ )
+ );
+ return true;
+ })
+ .catch(err => {
+ dispatch(
+ AppActions.reflectCreateEntries(
+ targetFiles.map(filePath => toFsEntry(filePath, true))
+ )
+ );
+ console.warn('At least one meta or thumb was not copied ' + err);
+ });
return true;
})
.catch(err => {
diff --git a/app/services/search-index.ts b/app/services/search-index.ts
index 880a52a27..bb4e18a51 100644
--- a/app/services/search-index.ts
+++ b/app/services/search-index.ts
@@ -62,6 +62,17 @@ const GlobalSearch = (function() {
}
}
},
+ reflectDeleteEntries: (paths: string[]) => {
+ if (!index || index.length < 1) {
+ return;
+ }
+ for (let i = 0; i < index.length; i += 1) {
+ if (paths.some(path => index[i].path === path)) {
+ index = index.splice(i, 1);
+ i -= 1;
+ }
+ }
+ },
reflectCreateEntry: (newEntry: TS.FileSystemEntry) => {
if (!index || index.length < 1) {
return;
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 465eec804..664344254 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -41,6 +41,7 @@ import {
getMetaFileLocationForDir,
extractContainingDirectoryPath,
extractDirectoryName,
+ extractFileName,
getThumbFileLocationForFile,
getThumbFileLocationForDirectory,
getBgndFileLocationForDirectory,
@@ -1546,6 +1547,22 @@ export function mergeFsEntryMeta(props: any = {}): TS.FileSystemEntryMeta {
};
}
+export function toFsEntry(path: string, isFile: boolean): TS.FileSystemEntry {
+ return {
+ uuid: getUuid(),
+ name: isFile
+ ? extractFileName(path, PlatformIO.getDirSeparator())
+ : extractDirectoryName(path, PlatformIO.getDirSeparator()),
+ isFile,
+ extension: extractFileExtension(path, PlatformIO.getDirSeparator()),
+ description: '',
+ tags: [],
+ size: 0,
+ lmdt: new Date().getTime(),
+ path
+ };
+}
+
export function createFsEntryMeta(
path: string,
props: any = {}
diff --git a/package.json b/package.json
index 8817980a8..a224092ae 100644
--- a/package.json
+++ b/package.json
@@ -65,8 +65,8 @@
"lint-styles": "stylelint --ignore-path .eslintignore '**/*.*(css|scss)' --syntax scss",
"lint-styles-fix": "npm run --silent lint-styles --fix; exit 0",
"postlint-styles-fix": "prettier --ignore-path .eslintignore --single-quote --write '**/*.{css,scss}'",
- "minio-start": "./tests/bin/minio server ./tests/testdata/file-structure",
- "minio-start-windows": ".\\tests\\bin\\minio.exe server ./tests/testdata/file-structure",
+ "minio-start": "./tests/bin/minio server ./tests/testdata-tmp/file-structure",
+ "minio-start-windows": ".\\tests\\bin\\minio.exe server ./tests/testdata-tmp/file-structure",
"package": "npm run build && npm run package-win && npm run package-linux && npm run package-mac && npm run package-web",
"package-android": "npm run build-cordova && cd cordova && npm install && cordova build --release android",
"package-ci": "npm run postinstall && npm run build && electron-builder --publish always",
diff --git a/tests/create-1000files-nothumbs.sh b/tests/create-1000files-nothumbs.sh
new file mode 100644
index 000000000..e967c33c9
--- /dev/null
+++ b/tests/create-1000files-nothumbs.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+testdir="./testdata-tmp/file-structure/supported-filestypes"
+dirpath="$testdir/1000files-nothumbs"
+jsonFile='{"appName":"TagSpaces","appVersion":"5.4.0","description":"","lastUpdated":1687873444575,"tags":[{"title":"1star","color":"#ffcc24","textcolor":"#ffffff","type":"sidecar"}],"id":"051cd049adad404c80d7d33e52feb8c2"}'
+
+mkdir -p "$dirpath"/.ts
+for i in $(seq 1 1000); do
+ cp "$testdir/sample.png" $(printf "$dirpath/testfile[tag1]%04u.png" $i)
+ echo "$jsonFile" > $(printf "$dirpath/.ts/testfile[tag1]%04u.png.json" $i)
+done