Skip to content

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

TSN197 - S3 rename dir support (#1352)

Stanimira2be3bb06c84
diff --git a/app/services/objectstore-io.ts b/app/services/objectstore-io.ts
index a6187c18a..28cd53243 100644
--- a/app/services/objectstore-io.ts
+++ b/app/services/objectstore-io.ts
@@ -26,7 +26,8 @@ import {
normalizePath,
getThumbFileLocationForFile,
getMetaFileLocationForFile,
- extractFileExtension
+ extractFileExtension,
+ cleanTrailingDirSeparator
} from '-/utils/paths';
import { FileSystemEntry } from '-/services/utils-io';
@@ -730,27 +731,63 @@ export default class ObjectStoreIO {
};
/**
- * Rename a directory TODO list and copy all content in new DIR
+ * Rename a directory
*/
- renameDirectoryPromise = (
+ renameDirectoryPromise = async (
dirPath: string,
newDirectoryPath: string
): Promise<Object> => {
- const newDirPath =
- extractParentDirectoryPath(dirPath, '/') + '/' + newDirectoryPath;
+ const parenDirPath = extractParentDirectoryPath(dirPath, '/');
+ const newDirPath = this.normalizeRootPath(
+ parenDirPath + '/' + newDirectoryPath
+ );
console.log('Renaming directory: ' + dirPath + ' to ' + newDirPath);
if (dirPath === newDirPath) {
- return new Promise((resolve, reject) => {
- reject('Renaming directory failed, directories have the same path');
- });
+ return Promise.reject(
+ 'Renaming directory failed, directories have the same path'
+ );
}
- return this.objectStore
- .copyObject({
+
+ try {
+ const listParams = {
Bucket: this.config.bucketName,
- CopySource: this.config.bucketName + '/' + dirPath,
- Key: newDirPath
- })
- .promise();
+ Prefix: dirPath,
+ Delimiter: '/'
+ };
+ const listedObjects = await this.objectStore
+ .listObjectsV2(listParams)
+ .promise();
+
+ if (listedObjects.Contents.length > 0) {
+ const promises = [];
+ listedObjects.Contents.forEach(({ Key }) => {
+ if (Key.endsWith('/')) {
+ promises.push(this.createDirectoryPromise(newDirectoryPath));
+ } else {
+ promises.push(
+ this.copyFilePromise(
+ Key,
+ parenDirPath +
+ '/' +
+ Key.replace(normalizePath(dirPath), newDirectoryPath)
+ )
+ );
+ }
+ });
+
+ return Promise.all(promises).then(() =>
+ this.deleteDirectoryPromise(dirPath).then(() => newDirectoryPath)
+ );
+ } else {
+ // empty Dir
+ return this.createDirectoryPromise(newDirectoryPath).then(() =>
+ this.deleteDirectoryPromise(dirPath).then(() => newDirectoryPath)
+ );
+ }
+ } catch (e) {
+ console.log(e);
+ }
+ return Promise.reject('No directory exist:' + dirPath);
};
/**
@@ -770,7 +807,8 @@ export default class ObjectStoreIO {
deleteDirectoryPromise = async (path: string): Promise<Object> => {
const listParams = {
Bucket: this.config.bucketName,
- Prefix: path
+ Prefix: path,
+ Delimiter: '/'
};
const listedObjects = await this.objectStore
.listObjectsV2(listParams)
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index 66a707ab8..dc6a1f2a1 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -217,10 +217,10 @@ export default class PlatformIO {
newDirName: string
): Promise<any> => {
if (objectStoreAPI) {
- // return objectStoreAPI.renameDirectoryPromise(dirPath, newDirName);
- return Promise.reject(
+ return objectStoreAPI.renameDirectoryPromise(dirPath, newDirName);
+ /* return Promise.reject(
'Renaming directories not supported on this platform'
- );
+ ); */
}
return nativeAPI.renameDirectoryPromise(dirPath, newDirName);
};
diff --git a/package.json b/package.json
index f0351d7b7..27f2558cd 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"build": "rimraf app/dist && yarn version-meta && concurrently \"yarn build-main\" \"yarn build-renderer\" \"yarn build-worker\" \"yarn build-web\"",
"build-dll": "cross-env NODE_ENV=development webpack --config ./configs/webpack.config.renderer.dev.dll.babel.js --colors",
"build-e2e": "cross-env E2E_BUILD=true yarn build",
+ "build-e2e-dev": "rimraf app/dist && yarn version-meta && cross-env E2E_BUILD=true concurrently \"yarn build-main\" \"yarn build-renderer\" \"yarn build-worker\" \"yarn build-web-dev\"",
"build-main": "cross-env NODE_ENV=production webpack --config ./configs/webpack.config.main.prod.babel.js --colors",
"build-renderer": "cross-env NODE_ENV=production webpack --config ./configs/webpack.config.renderer.prod.babel.js --colors",
"build-worker": "cross-env NODE_ENV=production webpack --config ./configs/webpack.config.worker.prod.babel.js --colors",
diff --git a/tests/e2e/fileopener.e2e.js b/tests/e2e/fileopener.e2e.js
index 9920bde92..57734989b 100644
--- a/tests/e2e/fileopener.e2e.js
+++ b/tests/e2e/fileopener.e2e.js
@@ -131,7 +131,7 @@ describe('TST08 - File folder properties', () => {
it.skip('TST0806 - Download file [Electron, manual]', async () => {});
- it('TST0807 - Rename opened folder [electron]', async () => {
+ it('TST0807 - Rename opened folder [web,minio,electron]', async () => {
const newTile = 'folderRenamed';
// open folderProperties
await openContextEntryMenu(selectorFolder, 'showProperties');
@@ -217,7 +217,7 @@ describe('TST08 - File folder properties', () => {
expect(propsFileName).not.toBe(firstFileName);
});
- it('TST0814 - Open file fullscreen and exit with close button [ web,minio,electron]', async () => {
+ it('TST0814 - Open file fullscreen and exit with close button [web,minio,electron]', async () => {
// open fileProperties
await clickOn(selectorFile);
await clickOn('[data-tid=fileContainerSwitchToFullScreen]');
diff --git a/tests/e2e/folder.e2e.js b/tests/e2e/folder.e2e.js
index e71fe2e05..366654e76 100644
--- a/tests/e2e/folder.e2e.js
+++ b/tests/e2e/folder.e2e.js
@@ -23,7 +23,7 @@ import { renameFolder } from './test-utils';
// export const perspectiveGridTable = '//*[@data-tid="perspectiveGridFileTable"]';
// const newDirectoryName = 'newDirectory';
-describe('TST01 - Folder management [electron]', () => {
+describe('TST01 - Folder management', () => {
beforeEach(async () => {
if (global.isMinio) {
await createMinioLocation('', defaultLocationName, true);
@@ -35,7 +35,7 @@ describe('TST01 - Folder management [electron]', () => {
});
// TODO minio
- it('TST0101 - Create subfolder [electron]', async () => {
+ it('TST0101 - Create subfolder [web,minio,electron]', async () => {
const testFolder = await createNewDirectory();
await expectElementExist('[data-tid=fsEntryName_' + testFolder + ']');
await doubleClickOn('[data-tid=fsEntryName_' + testFolder + ']');
@@ -47,7 +47,7 @@ describe('TST01 - Folder management [electron]', () => {
});
// TODO minio
- it('TST0102 - Reload folder [electron]', async () => {
+ it('TST0102 - Reload folder [web,minio,electron]', async () => {
const testFolder = await createNewDirectory();
await doubleClickOn('[data-tid=fsEntryName_' + testFolder + ']');
await reloadDirectory();
@@ -59,21 +59,23 @@ describe('TST01 - Folder management [electron]', () => {
);
});
- it.skip('TST0103 - Rename folder [TODO]', async () => {
+ it('TST0103 - Rename folder [web,minio,electron]', async () => {
const testFolder = await createNewDirectory();
await doubleClickOn('[data-tid=fsEntryName_' + testFolder + ']');
const newDirectoryName = await renameFolder();
- //await openParentDir();
- /*await expectElementExist('[data-tid=fsEntryName_' + newDirectoryName + ']');
- await openEntry(newDirectoryName);
+ await global.client.pause(500);
+ await clickOn('[data-tid=gridPerspectiveOnBackButton]');
+ await expectElementExist('[data-tid=fsEntryName_' + newDirectoryName + ']');
+ // cleanup
+ await doubleClickOn('[data-tid=fsEntryName_' + newDirectoryName + ']');
await deleteDirectory();
await expectElementExist(
- '[data-tid=fsEntryName_' + newDirectoryName + ']',
- false
- );*/
+ '[data-tid=fsEntryName_' + newDirectoryName + ']',
+ false
+ );
});
- it('TST0104 - Delete empty folder [electron]', async () => {
+ it('TST0104 - Delete empty folder [web,minio,electron]', async () => {
// await setSettings('[data-tid=settingsSetUseTrashCan]');
// await global.client.pause(500);
const testFolder = await createNewDirectory();
diff --git a/tests/e2e/general.e2e.js b/tests/e2e/general.e2e.js
index f1ae9c2d2..09a0726ed 100644
--- a/tests/e2e/general.e2e.js
+++ b/tests/e2e/general.e2e.js
@@ -6,8 +6,7 @@ import {
defaultLocationPath,
defaultLocationName,
closeFileProperties,
- createMinioLocation,
- deleteFirstFile
+ createMinioLocation
} from './location.helpers';
import {
reloadDirectory,
@@ -18,7 +17,6 @@ import {
newTEXTFile,
closeOpenedFile,
deleteDirectory,
- returnDirectoryBack,
clickOn,
expectElementExist,
selectorFile,
@@ -68,13 +66,11 @@ describe('TST51 - Perspective Grid [general]', () => {
await closeOpenedFile();
// await reloadDirectory();
await expectElementExist(selectorFile, true);
- /*await global.client.pause(500);
- await returnDirectoryBack();*/
+ /*await global.client.pause(500);*/
// delete directory
// await deleteFirstFile();
await deleteDirectory(testFolder);
- // await returnDirectoryBack();
await global.client.pause(500);
await expectElementExist(
'[data-tid=fsEntryName_' + testFolder + ']',
diff --git a/tests/e2e/general.helpers.js b/tests/e2e/general.helpers.js
index 2f826d214..a06e09e78 100644
--- a/tests/e2e/general.helpers.js
+++ b/tests/e2e/general.helpers.js
@@ -598,17 +598,6 @@ export async function deleteDirectory() {
await delay(500);*/
}
-export async function returnDirectoryBack() {
- await clickOn('[data-tid=gridPerspectiveOnBackButton]');
- /*
- await delay(500);
- const backButton = await global.client.$(
- '[data-tid=gridPerspectiveOnBackButton]'
- );
- await backButton.click();
- await delay(500);*/
-}
-
export async function toHaveText() {
await delay(500);
const file = await global.client.$(perspectiveGridTable + firstFile);
diff --git a/tests/e2e/hook.js b/tests/e2e/hook.js
index d064ba824..46adbdc16 100644
--- a/tests/e2e/hook.js
+++ b/tests/e2e/hook.js
@@ -74,7 +74,8 @@ export async function startSpectronApp() {
'goog:chromeOptions': {
w3c: true,
args: chromeDriverArgs
- }
+ },
+ // pageLoadStrategy: 'normal'
},
// Warns when a deprecated command is used
deprecationWarnings: true,
diff --git a/tests/e2e/location.helpers.js b/tests/e2e/location.helpers.js
index 1dbd6a6dd..c0cc0c68d 100644
--- a/tests/e2e/location.helpers.js
+++ b/tests/e2e/location.helpers.js
@@ -60,7 +60,9 @@ export async function createMinioLocation(
// Check if location not exist (from extconfig.js)
if (locationName !== lastLocationTID) {
await clickOn('[data-tid=createNewLocation]');
- // await clickOn('[data-tid=objectStorageLocation]');
+ if (global.isMinio) {
+ await clickOn('[data-tid=objectStorageLocation]');
+ }
await clickOn('[data-tid=switchAdvancedModeTID]');
// SET LOCATION NAME
diff --git a/tests/e2e/perspective-grid-right-button.e2e.js b/tests/e2e/perspective-grid-right-button.e2e.js
index 4f3fcc7cd..c557e096b 100644
--- a/tests/e2e/perspective-grid-right-button.e2e.js
+++ b/tests/e2e/perspective-grid-right-button.e2e.js
@@ -224,7 +224,7 @@ describe('TST50** - Right button on a file', () => {
// check parent directory
});
- test('TST5027 - Open containing folder [electron,web]', async () => {
+ test('TST5027 - Open containing folder [web,minio,electron]', async () => {
if (!global.isMinio) {
// Show in File Manager option is missing for Minio Location
await searchEngine('txt');
@@ -250,7 +250,7 @@ describe('TST50** - Right button on a file', () => {
/**
* TODO github minio (expected selector to exist=false after 5s)
*/
- test('TST5028 - Move - Copy file (file menu) [electron]', async () => {
+ test('TST5028 - Move - Copy file (file menu) [minio,electron]', async () => {
// Move file in child folder
await searchEngine('eml');
await openContextEntryMenu(
@@ -306,10 +306,7 @@ describe('TST50** - Right button on a file', () => {
expect(firstFileName).toBe(undefined); //'sample.eml');
});
- /**
- * minio not support rename folder
- */
- test('TST5034 - Rename directory (directory menu) [electron]', async () => {
+ test('TST5034 - Rename directory (directory menu) [web,minio,electron]', async () => {
const newDirName = 'new_dir_name';
await openContextEntryMenu(
perspectiveGridTable + firstFolder,
@@ -339,7 +336,7 @@ describe('TST50** - Right button on a file', () => {
/**
* delete dir is not supported on minio
*/
- test('TST5035 - Delete directory (directory menu) [electron]', async () => {
+ test('TST5035 - Delete directory (directory menu) [web,minio,electron]', async () => {
// await setSettings('[data-tid=settingsSetUseTrashCan]');
// await global.client.pause(500);
await doubleClickOn(selectorFolder);
diff --git a/tests/e2e/tag.e2e.js b/tests/e2e/tag.e2e.js
index 158f88516..d4de3ae07 100644
--- a/tests/e2e/tag.e2e.js
+++ b/tests/e2e/tag.e2e.js
@@ -85,7 +85,7 @@ describe('TST04 - Testing the tag library:', () => {
);
});
- it('TST0404 - Change default tag group tag colors [minio,electron]', async () => {
+ it('TST0404 - Change default tag group tag colors [web,minio,electron]', async () => {
await createTagGroup(testGroup);
await clickOn('[data-tid=tagLibraryMoreButton_' + testGroup + ']');
await clickOn('[data-tid=editTagGroup]');
@@ -110,10 +110,11 @@ describe('TST04 - Testing the tag library:', () => {
const colorElem = await global.client.$(
'[data-tid=editTagGroupBackgroundColor]'
);
- const color = await colorElem.getCSSProperty('background');
+ let colorStyle = await colorElem.getAttribute('style');
+ // const color = await colorElem.getCSSProperty('background');
const rgb2hex = require('rgb2hex');
- const hex = rgb2hex(color.value);
+ const hex = rgb2hex(colorStyle); //color.value);
expect(hex.hex).toBe('#000000'); //'rgb(0,0,0)');
await clickOn('[data-tid=editTagGroupConfirmButton]');
});
@@ -201,9 +202,10 @@ describe('TST04 - Testing the tag library:', () => {
const colorElem = await global.client.$(
'[data-tid=createTagGroupBackgroundColor]'
);
- const color = await colorElem.getCSSProperty('background');
+ let colorStyle = await colorElem.getAttribute('style');
+ // const color = await colorElem.getCSSProperty('background');
const rgb2hex = require('rgb2hex');
- const hex = rgb2hex(color.value);
+ const hex = rgb2hex(colorStyle);// color.value);
expect(hex.hex).toBe('#000000'); //'rgb(0,0,0)');
await clickOn('[data-tid=createTagGroupCancelButton]');
diff --git a/tests/e2e/test-utils.js b/tests/e2e/test-utils.js
index 6709cad15..2fd2e0194 100644
--- a/tests/e2e/test-utils.js
+++ b/tests/e2e/test-utils.js
@@ -85,7 +85,3 @@ export async function renameFolder() {
await clickOn('[data-tid=confirmRenameDirectory]');
return newDirectoryName;
}
-
-export async function openParentDir() {
- await clickOn('[data-tid=gridPerspectiveOnBackButton]');
-}