Skip to content

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

TSN536- Rethink directory watching due to new indexing strategy (#1358)

Stanimir17cedbdf8d2d
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index 6ed566b01..e39168598 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -24,7 +24,8 @@ import MenuItem from '@material-ui/core/MenuItem';
import Divider from '@material-ui/core/Divider';
import OpenFile from '@material-ui/icons/SubdirectoryArrowRight';
import OpenFileNatively from '@material-ui/icons/Launch';
-import OpenContainingFolder from '@material-ui/icons/FolderOpen';
+import OpenParentFolder from '@material-ui/icons/FolderOpen';
+import OpenFolderInternally from '@material-ui/icons/Folder';
import AddRemoveTags from '@material-ui/icons/Loyalty';
import MoveCopy from '@material-ui/icons/FileCopy';
import ImageIcon from '@material-ui/icons/Image';
@@ -39,6 +40,7 @@ import {
setFolderThumbnailPromise
} from '-/services/utils-io';
import { Pro } from '-/pro';
+import { extractParentDirectoryPath } from '-/utils/paths';
interface Props {
anchorEl: Element;
@@ -49,6 +51,7 @@ interface Props {
openMoveCopyFilesDialog: () => void;
openAddRemoveTagsDialog: () => void;
openFsEntry: (fsEntry: FileSystemEntry) => void;
+ loadDirectoryContent: (path: string) => void;
openFileNatively: (path: string) => void;
showInFileManager: (path: string) => void;
showNotification: (
@@ -127,6 +130,17 @@ const FileMenu = (props: Props) => {
}
}
+ function openParentFolderInternally() {
+ props.onClose();
+ if (props.selectedFilePath) {
+ const parentFolder = extractParentDirectoryPath(
+ props.selectedFilePath,
+ PlatformIO.getDirSeparator()
+ );
+ props.loadDirectoryContent(parentFolder);
+ }
+ }
+
function openFile() {
props.onClose();
if (props.selectedFilePath) {
@@ -150,12 +164,23 @@ const FileMenu = (props: Props) => {
<div style={{ overflowY: 'hidden' }}>
<Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}>
{props.selectedEntries.length < 2 && (
- <MenuItem data-tid="fileMenuOpenFile" onClick={openFile}>
- <ListItemIcon>
- <OpenFile />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:openFile')} />
- </MenuItem>
+ <>
+ <MenuItem data-tid="fileMenuOpenFile" onClick={openFile}>
+ <ListItemIcon>
+ <OpenFile />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:openFile')} />
+ </MenuItem>
+ <MenuItem
+ data-tid="fileMenuOpenParentFolderInternally"
+ onClick={openParentFolderInternally}
+ >
+ <ListItemIcon>
+ <OpenParentFolder />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:openParentFolder')} />
+ </MenuItem>
+ </>
)}
{!(PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb) &&
props.selectedEntries.length < 2 && (
@@ -174,7 +199,7 @@ const FileMenu = (props: Props) => {
onClick={showInFileManager}
>
<ListItemIcon>
- <OpenContainingFolder />
+ <OpenFolderInternally />
</ListItemIcon>
<ListItemText primary={i18n.t('core:showInFileManager')} />
</MenuItem>
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 12eee6246..dc07e9e09 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -143,6 +143,7 @@
"openFile": "Open File",
"downloadFile": "Download",
"openFileNatively": "Open File Natively",
+ "openParentFolder": "Open Parent Folder",
"openContainingFolder": "Open Containing Folder",
"showInFileManager": "Show in File Manager",
"fullscreen": "Open in Fullscreen",
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index 414c9598c..3f0319caa 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -805,6 +805,7 @@ const GridPerspective = (props: Props) => {
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
openFsEntry={props.openFsEntry}
openFileNatively={props.openFileNatively}
+ loadDirectoryContent={props.loadDirectoryContent}
showInFileManager={props.showInFileManager}
showNotification={props.showNotification}
isReadOnlyMode={props.isReadOnlyMode}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index dc568cae3..01b5c62d2 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -923,42 +923,42 @@ export const actions = {
);
}
},
+ loadDirectoryContentInt: (
+ directoryPath: string,
+ fsEntryMeta?: FileSystemEntryMeta
+ ) => (dispatch: (actions: Object) => void, getState: () => any) => {
+ const { settings } = getState();
+ dispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)
+ // dispatch(actions.setCurrentDirectoryColor('')); // this is to reset color only
+ dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
+ PlatformIO.listDirectoryPromise(directoryPath, false)
+ .then(results => {
+ prepareDirectoryContent(
+ results,
+ directoryPath,
+ settings,
+ dispatch,
+ getState,
+ fsEntryMeta
+ );
+ return true;
+ })
+ .catch(error => {
+ console.timeEnd('listDirectoryPromise');
+ dispatch(actions.loadDirectoryFailure(error)); // Currently this is never called, due the promise always resolve
+ });
+ },
loadDirectoryContent: (directoryPath: string) => (
- dispatch: (actions: Object) => void,
- getState: () => any
+ dispatch: (actions: Object) => void
) => {
console.time('listDirectoryPromise');
- const { settings } = getState();
window.walkCanceled = false;
- function loadDirectoryContentInt(fsEntryMeta?: FileSystemEntryMeta) {
- // Uncomment the following line will to clear all content before loading new dir content
- dispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)
- // dispatch(actions.setCurrentDirectoryColor('')); // this is to reset color only
- dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
- PlatformIO.listDirectoryPromise(directoryPath, false)
- .then(results => {
- prepareDirectoryContent(
- results,
- directoryPath,
- settings,
- dispatch,
- getState,
- fsEntryMeta
- );
- return true;
- })
- .catch(error => {
- console.timeEnd('listDirectoryPromise');
- dispatch(actions.loadDirectoryFailure(error)); // Currently this is never called, due the promise always resolve
- });
- }
-
loadMetaDataPromise(
normalizePath(directoryPath) + PlatformIO.getDirSeparator()
)
.then(fsEntryMeta => {
- loadDirectoryContentInt(fsEntryMeta);
+ dispatch(actions.loadDirectoryContentInt(directoryPath, fsEntryMeta));
/* if (fsEntryMeta.color) { // TODO rethink this states changes are expensive
dispatch(actions.setCurrentDirectoryColor(fsEntryMeta.color));
}
@@ -970,7 +970,7 @@ export const actions = {
})
.catch(err => {
console.log('Error loading meta of the current folder' + err);
- loadDirectoryContentInt();
+ dispatch(actions.loadDirectoryContentInt(directoryPath));
});
},
loadDirectorySuccess: (
@@ -1358,7 +1358,8 @@ export const actions = {
});
},
openLocation: (location: Location) => (
- dispatch: (actions: Object) => void
+ dispatch: (actions: Object) => void,
+ getState: () => any
) => {
if (Pro && Pro.Watcher) {
Pro.Watcher.stopWatching();
@@ -1394,7 +1395,14 @@ export const actions = {
dispatch(actions.changeLocation(location));
dispatch(actions.loadDirectoryContent(getLocationPath(location)));
if (Pro && Pro.Watcher && location.watchForChanges) {
- Pro.Watcher.watchFolder(getLocationPath(location), dispatch, actions);
+ const perspective = getCurrentDirectoryPerspective(getState());
+ const depth = perspective === perspectives.KANBAN ? 3 : 1;
+ Pro.Watcher.watchFolder(
+ getLocationPath(location),
+ dispatch,
+ actions,
+ depth
+ );
}
}
},
@@ -1466,6 +1474,21 @@ export const actions = {
type: types.SET_READONLYMODE,
isReadOnlyMode
}),
+ reflectUpdateOpenedFileContent: (entryPath: string) => (
+ dispatch: (actions: Object) => void,
+ getState: () => any
+ ) => {
+ const { openedFiles } = getState().app;
+ if (openedFiles && openedFiles.length > 0) {
+ const openedFile: OpenedEntry = openedFiles.find(
+ obj => obj.path === entryPath
+ );
+ if (openedFile) {
+ openedFile.shouldReload = true;
+ dispatch(actions.addToEntryContainer(openedFile));
+ }
+ }
+ },
updateOpenedFile: (
entryPath: string,
fsEntryMeta: any // FileSystemEntryMeta,
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index dc6a1f2a1..0b4909ee1 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -156,11 +156,32 @@ export default class PlatformIO {
return nativeAPI.getPropertiesPromise(path);
};
+ static ignoreByWatcher = (...paths) => {
+ if (Pro && Pro.Watcher && Pro.Watcher.isWatching()) {
+ for (let i = 0; i < paths.length; i += 1) {
+ Pro.Watcher.addToIgnored(paths[i]);
+ }
+ }
+ };
+
+ static deignoreByWatcher = (...paths) => {
+ if (Pro && Pro.Watcher && Pro.Watcher.isWatching()) {
+ for (let i = 0; i < paths.length; i += 1) {
+ Pro.Watcher.removeFromIgnored(paths[i]);
+ }
+ }
+ };
+
static createDirectoryPromise = (dirPath: string): Promise<any> => {
if (objectStoreAPI) {
return objectStoreAPI.createDirectoryPromise(dirPath);
}
- return nativeAPI.createDirectoryPromise(dirPath);
+ PlatformIO.ignoreByWatcher(dirPath);
+
+ return nativeAPI.createDirectoryPromise(dirPath).then(result => {
+ PlatformIO.deignoreByWatcher(dirPath);
+ return result;
+ });
};
static copyFilePromise = async (
@@ -199,7 +220,14 @@ export default class PlatformIO {
if (objectStoreAPI) {
return objectStoreAPI.copyFilePromise(sourceFilePath, targetFilePath);
}
- return nativeAPI.copyFilePromise(sourceFilePath, targetFilePath);
+ PlatformIO.ignoreByWatcher(targetFilePath);
+
+ return nativeAPI
+ .copyFilePromise(sourceFilePath, targetFilePath)
+ .then(result => {
+ PlatformIO.deignoreByWatcher(targetFilePath);
+ return result;
+ });
};
static renameFilePromise = (
@@ -209,7 +237,12 @@ export default class PlatformIO {
if (objectStoreAPI) {
return objectStoreAPI.renameFilePromise(filePath, newFilePath);
}
- return nativeAPI.renameFilePromise(filePath, newFilePath);
+ PlatformIO.ignoreByWatcher(filePath, newFilePath);
+
+ return nativeAPI.renameFilePromise(filePath, newFilePath).then(result => {
+ PlatformIO.deignoreByWatcher(filePath, newFilePath);
+ return result;
+ });
};
static renameDirectoryPromise = (
@@ -218,11 +251,15 @@ export default class PlatformIO {
): Promise<any> => {
if (objectStoreAPI) {
return objectStoreAPI.renameDirectoryPromise(dirPath, newDirName);
- /* return Promise.reject(
- 'Renaming directories not supported on this platform'
- ); */
}
- return nativeAPI.renameDirectoryPromise(dirPath, newDirName);
+ PlatformIO.ignoreByWatcher(dirPath, newDirName);
+
+ return nativeAPI
+ .renameDirectoryPromise(dirPath, newDirName)
+ .then(result => {
+ PlatformIO.deignoreByWatcher(dirPath, newDirName);
+ return result;
+ });
};
static loadTextFilePromise = (
@@ -253,7 +290,14 @@ export default class PlatformIO {
if (objectStoreAPI) {
return objectStoreAPI.saveFilePromise(filePath, content, overwrite);
}
- return nativeAPI.saveFilePromise(filePath, content, overwrite);
+ PlatformIO.ignoreByWatcher(filePath);
+
+ return nativeAPI
+ .saveFilePromise(filePath, content, overwrite)
+ .then(result => {
+ PlatformIO.deignoreByWatcher(filePath);
+ return result;
+ });
};
static saveTextFilePromise = (
@@ -264,7 +308,15 @@ export default class PlatformIO {
if (objectStoreAPI) {
return objectStoreAPI.saveTextFilePromise(filePath, content, overwrite);
}
- return nativeAPI.saveTextFilePromise(filePath, content, overwrite);
+
+ PlatformIO.ignoreByWatcher(filePath);
+
+ return nativeAPI
+ .saveTextFilePromise(filePath, content, overwrite)
+ .then(result => {
+ PlatformIO.deignoreByWatcher(filePath);
+ return result;
+ });
};
static saveBinaryFilePromise = (
@@ -284,12 +336,15 @@ export default class PlatformIO {
onUploadProgress
);
}
+ PlatformIO.ignoreByWatcher(filePath);
+
return nativeAPI
.saveBinaryFilePromise(filePath, content, overwrite)
.then(succeeded => {
if (succeeded && onUploadProgress) {
onUploadProgress({ key: filePath, loaded: 1, total: 1 }, undefined);
}
+ PlatformIO.deignoreByWatcher(filePath);
return succeeded;
});
};
@@ -301,7 +356,12 @@ export default class PlatformIO {
if (objectStoreAPI) {
return objectStoreAPI.deleteFilePromise(path, useTrash);
}
- return nativeAPI.deleteFilePromise(path, useTrash);
+ PlatformIO.ignoreByWatcher(path);
+
+ return nativeAPI.deleteFilePromise(path, useTrash).then(result => {
+ PlatformIO.deignoreByWatcher(path);
+ return result;
+ });
};
static deleteDirectoryPromise = (
@@ -310,11 +370,13 @@ export default class PlatformIO {
): Promise<any> => {
if (objectStoreAPI) {
return objectStoreAPI.deleteDirectoryPromise(path, useTrash);
- /* return Promise.reject(
- 'Deleting directories not supported on this platform'
- ); */
}
- return nativeAPI.deleteDirectoryPromise(path, useTrash);
+ PlatformIO.ignoreByWatcher(path);
+
+ return nativeAPI.deleteDirectoryPromise(path, useTrash).then(result => {
+ PlatformIO.deignoreByWatcher(path);
+ return result;
+ });
};
static openDirectory = (dirPath: string): void =>
diff --git a/app/utils/paths.ts b/app/utils/paths.ts
index 56abe7586..61d18045f 100644
--- a/app/utils/paths.ts
+++ b/app/utils/paths.ts
@@ -90,6 +90,25 @@ export function getMetaFileLocationForFile(
);
}
+export function getFileLocationFromMetaFile(
+ entryPath: string,
+ dirSeparator: string // = AppConfig.dirSeparator
+) {
+ let containingFolder = extractContainingDirectoryPath(
+ entryPath,
+ dirSeparator
+ );
+ containingFolder = containingFolder.replace(
+ dirSeparator + AppConfig.metaFolder,
+ ''
+ );
+ const fileName = extractFileName(entryPath, dirSeparator).replace(
+ AppConfig.metaFileExt,
+ ''
+ );
+ return containingFolder + dirSeparator + fileName;
+}
+
export function getThumbFileLocationForFile(
entryPath: string,
dirSeparator: string // = AppConfig.dirSeparator
diff --git a/package.json b/package.json
index 46c0e0bcc..793cd146d 100644
--- a/package.json
+++ b/package.json
@@ -247,7 +247,7 @@
"aws-amplify": "^3.3.19",
"aws-sdk": "^2.652.0",
"babel-polyfill": "^6.26.0",
- "chokidar": "^3.4.3",
+ "chokidar": "^3.5.1",
"classnames": "^2.2.6",
"clone": "^2.1.2",
"core-js": "2",
diff --git a/yarn.lock b/yarn.lock
index bb35d5bd6..8c480f5bd 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6114,7 +6114,7 @@ chokidar@^2.1.8:
optionalDependencies:
fsevents "^1.2.7"
-chokidar@^3.4.1, chokidar@^3.4.3:
+chokidar@^3.4.1:
version "3.4.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.3.tgz#c1df38231448e45ca4ac588e6c79573ba6a57d5b"
integrity sha512-DtM3g7juCXQxFVSNPNByEC2+NImtBuxQQvWlHunpJIS5Ocr0lG306cC7FCi7cEA0fzmybPUIl4txBIobk1gGOQ==
@@ -6129,6 +6129,21 @@ chokidar@^3.4.1, chokidar@^3.4.3:
optionalDependencies:
fsevents "~2.1.2"
+chokidar@^3.5.1:
+ version "3.5.1"
+ resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a"
+ integrity sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==
+ dependencies:
+ anymatch "~3.1.1"
+ braces "~3.0.2"
+ glob-parent "~5.1.0"
+ is-binary-path "~2.1.0"
+ is-glob "~4.0.1"
+ normalize-path "~3.0.0"
+ readdirp "~3.5.0"
+ optionalDependencies:
+ fsevents "~2.3.1"
+
chownr@^1.0.1, chownr@^1.1.1:
version "1.1.4"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
@@ -9215,6 +9230,11 @@ fsevents@^2.1.2, fsevents@~2.1.2:
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e"
integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==
+fsevents@~2.3.1:
+ version "2.3.2"
+ resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
+ integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
+
fstream-ignore@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/fstream-ignore/-/fstream-ignore-1.0.5.tgz#9c31dae34767018fe1d249b24dada67d092da105"