Skip to content

Commit

Permalink
Merge pull request #103 from trganda/develop
Browse files Browse the repository at this point in the history
fix: delete unrelate empty folder
  • Loading branch information
trganda authored Feb 2, 2024
2 parents d216d38 + 7d0e96c commit b458227
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ArrangeHandler } from "./arrange";
import { CreateHandler } from "./create";
import { isExcluded } from "./exclude";
import { getMetadata } from "./settings/metadata";
import { path } from "./lib/path";

export default class AttachmentManagementPlugin extends Plugin {
settings: AttachmentManagementPluginSettings;
Expand Down Expand Up @@ -253,19 +252,14 @@ export default class AttachmentManagementPlugin extends Plugin {
await this.saveSettings();

const oldMetadata = getMetadata(oldPath);
// if the user have used the ${date} in `Attachment path` this could be not working, since the date will be changed.
// fixed by travese from parent folder
// if the user have used the ${date} in `Attachment path` this could be not working, since the date will be change.
const oldAttachPath = oldMetadata.getAttachmentPath(setting, this.settings.dateFormat);
this.app.vault.adapter.exists(path.dirname(oldAttachPath)).then((exists) => {
this.app.vault.adapter.exists(oldAttachPath).then((exists) => {
if (exists) {
this.app.vault.adapter.list(path.dirname(oldAttachPath)).then((data) => {
data.folders.forEach((folder) => {
checkEmptyFolder(this.app.vault.adapter, folder).then((empty) => {
if (empty) {
this.app.vault.adapter.rmdir(folder, true);
}
});
});
checkEmptyFolder(this.app.vault.adapter, oldAttachPath).then((empty) => {
if (empty) {
this.app.vault.adapter.rmdir(oldAttachPath, true);
}
});
}
});
Expand Down Expand Up @@ -294,16 +288,12 @@ export default class AttachmentManagementPlugin extends Plugin {
const oldMetadata = getMetadata(file.path);
const { setting } = getOverrideSetting(this.settings, file);
const oldAttachPath = oldMetadata.getAttachmentPath(setting, this.settings.dateFormat);
this.app.vault.adapter.exists(path.dirname(oldAttachPath), true).then((exists) => {
this.app.vault.adapter.exists(oldAttachPath, true).then((exists) => {
if (exists) {
this.app.vault.adapter.list(path.dirname(oldAttachPath)).then((data) => {
data.folders.forEach((folder) => {
checkEmptyFolder(this.app.vault.adapter, folder).then((empty) => {
if (empty) {
this.app.vault.adapter.rmdir(folder, true);
}
});
});
checkEmptyFolder(this.app.vault.adapter, oldAttachPath).then((empty) => {
if (empty) {
this.app.vault.adapter.rmdir(oldAttachPath, true);
}
});
}
});
Expand Down

0 comments on commit b458227

Please sign in to comment.