Skip to content

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

TSN598 - Add support for deleting directories containing files on AWS (#1351)

Stanimir27505d2dbff3
diff --git a/app/services/objectstore-io.ts b/app/services/objectstore-io.ts
index e2aa902e7..2c0cffff7 100644
--- a/app/services/objectstore-io.ts
+++ b/app/services/objectstore-io.ts
@@ -764,16 +764,42 @@ export default class ObjectStoreIO {
.promise();
/**
- * Delete a specified directory, the directory should be empty, if the trash can functionality is not enabled (partial: works for files and empty dirs)
- * TODO empty dir (its have invisible .ts dir)
+ * Delete a specified directory
*/
- deleteDirectoryPromise = (path: string): Promise<Object> =>
- this.objectStore
+ deleteDirectoryPromise = async (path: string): Promise<Object> => {
+ const listParams = {
+ Bucket: this.config.bucketName,
+ Prefix: path
+ };
+ const listedObjects = await this.objectStore
+ .listObjectsV2(listParams)
+ .promise();
+
+ if (listedObjects.Contents.length > 0) {
+ const deleteParams = {
+ Bucket: this.config.bucketName,
+ Delete: { Objects: [] }
+ };
+
+ listedObjects.Contents.forEach(({ Key }) => {
+ deleteParams.Delete.Objects.push({ Key });
+ });
+
+ return this.objectStore.deleteObjects(deleteParams).promise();
+
+ /*if (!listedObjects.IsTruncated) {
+ return Promise.reject(
+ 'Folder is not empty:' + JSON.stringify(listedObjects)
+ );
+ }*/
+ }
+ return this.objectStore
.deleteObject({
Bucket: this.config.bucketName,
Key: path
})
.promise();
+ };
/**
* Choosing directory
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index f21133ad0..66a707ab8 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -309,10 +309,10 @@ export default class PlatformIO {
useTrash?: boolean
): Promise<any> => {
if (objectStoreAPI) {
- // return objectStoreAPI.deleteDirectoryPromise(path, useTrash);
- return Promise.reject(
+ return objectStoreAPI.deleteDirectoryPromise(path, useTrash);
+ /* return Promise.reject(
'Deleting directories not supported on this platform'
- );
+ ); */
}
return nativeAPI.deleteDirectoryPromise(path, useTrash);
};
diff --git a/tests/e2e/tag.e2e.js b/tests/e2e/tag.e2e.js
index d2d0af73e..158f88516 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 [web,minio,electron]', async () => {
+ it('TST0404 - Change default tag group tag colors [minio,electron]', async () => {
await createTagGroup(testGroup);
await clickOn('[data-tid=tagLibraryMoreButton_' + testGroup + ']');
await clickOn('[data-tid=editTagGroup]');