TagSpaces is an offline, open source, document manager with tagging support
fix move files (#2043)
Stanimirc1efd3811d09
diff --git a/package.json b/package.jsonindex d94d15ad1..ef8845d0d 100644--- a/package.json+++ b/package.json@@ -61,7 +61,7 @@"install-ext-node-win": "rimraf release/app/node_modules && npm install --prefix ./release/app --platform=win32 --arch=x64 && npm run generate-extensions","install-ext-web": "rimraf release/app/node_modules && npm install --prefix ./release/app && npm run generate-extensions","install-ext-web-check": "npx cross-env PD_PLATFORM=web node scripts/checkWSinstalled.js",- "link-ext": "export CDIR=$PWD && ln -sf $CDIR/release/app/node_modules/@tagspaces/extensions $CDIR/public/modules/@tagspaces/extensions && ln -sf $CDIR/release/app/node_modules/@tagspacespro/extensions $CDIR/public/modules/@tagspacespro/extensions",+ "link-ext": "node -r ts-node/register scripts/link-ext.ts","lint": "cross-env NODE_ENV=development eslint . --ext .js,.jsx,.ts,.tsx","lint-fix": "npm run --silent lint --fix; exit 0","postlint-fix": "prettier --ignore-path .eslintignore --single-quote --write '**/*.{*{js,jsx,json},babelrc,eslintrc,prettierrc,stylelintrc}'",@@ -71,6 +71,7 @@"linux-fix-sandbox": "sudo chown root:root node_modules/electron/dist/chrome-sandbox && sudo chmod 4755 node_modules/electron/dist/chrome-sandbox","minio-start": "./tests/bin/minio server ./tests/testdata-tmp/file-structure","minio-start-windows": ".\\tests\\bin\\minio.exe server ./tests/testdata-tmp/file-structure",+ "scope-login": "npm login --scope=@tagspacespro --registry=https://npm.pkg.github.com","package": "ts-node ./.erb/scripts/clean.js && npm run build && electron-builder build --publish never && npm run build:dll","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/scripts/link-ext.ts b/scripts/link-ext.tsnew file mode 100644index 000000000..78039aa0c--- /dev/null+++ b/scripts/link-ext.ts@@ -0,0 +1,41 @@+import fs from 'fs';+import webpackPaths from '../.erb/configs/webpack.paths';+import path from 'path';++const { releasePath, rootPath } = webpackPaths;++// Link extensions+const srcExt = path.join(releasePath, 'app/node_modules/@tagspaces/extensions');+const targetExt = path.join(rootPath, 'public/modules/@tagspaces/extensions');+try {+ if (fs.existsSync(targetExt)) {+ fs.unlinkSync(targetExt);+ }+} catch (err) {+ console.error('Error removing file:' + targetExt, err);+}++if (fs.existsSync(srcExt)) {+ fs.symlinkSync(srcExt, targetExt, 'junction');+}++// link Pro+const srcProExt = path.join(+ releasePath,+ 'app/node_modules/@tagspacespro/extensions',+);+const targetProExt = path.join(+ rootPath,+ 'public/modules/@tagspacespro/extensions',+);+try {+ if (fs.existsSync(targetProExt)) {+ fs.unlinkSync(targetProExt);+ }+} catch (err) {+ console.error('Error removing file:' + targetProExt, err);+}++if (fs.existsSync(srcProExt)) {+ fs.symlinkSync(srcProExt, targetProExt, 'junction');+}diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex d4f2bb6b5..62beddcae 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -39,7 +39,12 @@ import {getMetaDirectoryPath,} from '@tagspaces/tagspaces-common/paths';import PlatformIO from '-/services/platform-facade';-import { loadJSONFile, merge, updateFsEntries } from '-/services/utils-io';+import {+ loadJSONFile,+ merge,+ toFsEntry,+ updateFsEntries,+} from '-/services/utils-io';import AppConfig from '-/AppConfig';import { PerspectiveIDs } from '-/perspectives';import { updateHistory } from '-/utils/dom';@@ -251,47 +256,10 @@ export const DirectoryContentContextProvider = ({const reflectActions = async (actions) => {if (actions && actions.length > 0) {for (const action of actions) {- /// ADDif (action.action === 'add') {- const entryExist = currentDirectoryEntries.current.some(- (e) => e.path === action.entry.path,- );- if (entryExist) {- currentDirectoryEntries.current =- currentDirectoryEntries.current.map((e) =>- e.path === action.entry.path ? action.entry : e,- );- } else {- const dirPath = extractContainingDirectoryPath(- action.entry.path,- PlatformIO.getDirSeparator(),- );- if (- cleanTrailingDirSeparator(currentDirectoryPath.current) ===- cleanTrailingDirSeparator(dirPath)- ) {- currentDirectoryEntries.current.push(action.entry);- // reflect add KanBan folders visibility- await toggleDirVisibility(- { name: action.entry.name, uuid: action.entry.uuid },- dirPath,- false,- );- }- }- /// DELETE+ await reflectAddAction(action.entry);} else if (action.action === 'delete') {- let index = currentDirectoryEntries.current.findIndex(- (e) => e.path === action.entry.path,- );- if (index !== -1) {- if (!action.entry.isFile) {- if (action.entry.path === currentDirectoryPath) {- loadParentDirectoryContent();- }- }- currentDirectoryEntries.current.splice(index, 1);- }+ reflectDeleteAction(action.entry);/// RENAME} else if (action.action === 'update') {let index = currentDirectoryEntries.current.findIndex(@@ -337,6 +305,11 @@ export const DirectoryContentContextProvider = ({}}}+ } else if (action.action === 'move') {+ await reflectAddAction(action.entry);+ reflectDeleteAction(+ toFsEntry(action.oldEntryPath, action.entry.isFile),+ );}}// create a shallow copy to publish changes@@ -345,6 +318,49 @@ export const DirectoryContentContextProvider = ({}};+ async function reflectAddAction(entry: TS.FileSystemEntry) {+ const entryExist = currentDirectoryEntries.current.some(+ (e) => e.path === entry.path,+ );+ if (entryExist) {+ currentDirectoryEntries.current = currentDirectoryEntries.current.map(+ (e) => (e.path === entry.path ? entry : e),+ );+ } else {+ const dirPath = extractContainingDirectoryPath(+ entry.path,+ PlatformIO.getDirSeparator(),+ );+ if (+ cleanTrailingDirSeparator(currentDirectoryPath.current) ===+ cleanTrailingDirSeparator(dirPath)+ ) {+ currentDirectoryEntries.current.push(entry);+ // reflect add KanBan folders visibility+ await toggleDirVisibility(+ { name: entry.name, uuid: entry.uuid },+ dirPath,+ false,+ );+ }+ }+ }++ function reflectDeleteAction(entry: TS.FileSystemEntry) {+ let index = currentDirectoryEntries.current.findIndex(+ (e) => e.path === entry.path,+ );+ if (index !== -1) {+ if (!entry.isFile) {+ if (entry.path === currentDirectoryPath.current) {+ loadParentDirectoryContent();+ return;+ }+ }+ currentDirectoryEntries.current.splice(index, 1);+ }+ }+function getDefaultDirMeta(): TS.FileSystemEntryMeta {const perspective = getPerspective();const settings: TS.PerspectiveSettings = {diff --git a/src/renderer/hooks/PlatformFacadeContextProvider.tsx b/src/renderer/hooks/PlatformFacadeContextProvider.tsxindex ee0f57d62..51f8aeedf 100644--- a/src/renderer/hooks/PlatformFacadeContextProvider.tsx+++ b/src/renderer/hooks/PlatformFacadeContextProvider.tsx@@ -380,22 +380,6 @@ export const PlatformFacadeContextProvider = ({if (reflect) {reflectMoveFiles([[filePath, newFilePath]]);}- /*getAllPropertiesPromise(newFilePath).then(- (fsEntry: TS.FileSystemEntry) => {- if (reflect) {- setReflectActions(- {- action: 'delete',- entry: toFsEntry(filePath, true),- },- {- action: 'add',- entry: fsEntry,- },- );- }- },- );*/deignoreByWatcher(filePath, newFilePath);return result;});@@ -436,12 +420,9 @@ export const PlatformFacadeContextProvider = ({(newFsEntry: TS.FileSystemEntry) => {const actions: TS.EditAction[] = [{- action: 'delete',- entry: toFsEntry(job[0], true),- },- {- action: 'add',+ action: 'move',entry: newFsEntry,+ oldEntryPath: job[0],},];return actions;@@ -506,10 +487,11 @@ export const PlatformFacadeContextProvider = ({onProgress,).then((result) => {getAllPropertiesPromise(newDirPath).then((fsEntry: TS.FileSystemEntry) =>- setReflectActions(- { action: 'delete', entry: toFsEntry(param.path, false) },- { action: 'add', entry: fsEntry },- ),+ setReflectActions({+ action: 'move',+ entry: fsEntry,+ oldEntryPath: param.path,+ }),);deignoreByWatcher(param.path, newDirPath);diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.tsindex 8b4fb151b..00240c889 100644--- a/src/renderer/tagspaces.namespace.d.ts+++ b/src/renderer/tagspaces.namespace.d.ts@@ -100,7 +100,7 @@ export namespace TS {type Uuid = string;interface EditAction {- action: 'add' | 'delete' | 'update';+ action: 'add' | 'delete' | 'update' | 'move';entry: TS.FileSystemEntry;oldEntryPath?: string;}diff --git a/tsconfig.json b/tsconfig.jsonindex fd2a64737..a7b915af5 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -27,8 +27,8 @@"include": ["src/renderer/**/*.ts","src/renderer/**/*.tsx",- "extensions/tagspacespro/**/*.ts",- "extensions/tagspacespro/**/*.tsx",+ "node_modules/@tagspacespro/tagspacespro/**/*.ts",+ "node_modules/@tagspacespro/tagspacespro/**/*.tsx",],"exclude": ["test", "release/build", "release/app/dist", ".erb/dll"],// "exclude": [