diff --git a/src/local.ts b/src/local.ts index cd70e38..5bcc46b 100644 --- a/src/local.ts +++ b/src/local.ts @@ -50,6 +50,8 @@ export const getLocalEntityList = async ( } else { throw Error(`unexpected ${entry}`); } + + local.push(r); } if (syncConfigDir) { diff --git a/src/main.ts b/src/main.ts index bcdc281..30a3fc3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -240,7 +240,7 @@ export default class RemotelySavePlugin extends Plugin { () => self.saveSettings() ); const remoteEntityList = await client.listAllFromRemote(); - // log.debug(remoteEntityList); + log.debug(remoteEntityList); if (this.settings.currLogLevel === "info") { // pass @@ -269,7 +269,7 @@ export default class RemotelySavePlugin extends Plugin { this.app.vault.configDir, this.manifest.id ); - // log.info(localEntityList); + log.debug(localEntityList); if (this.settings.currLogLevel === "info") { // pass @@ -281,7 +281,7 @@ export default class RemotelySavePlugin extends Plugin { this.db, this.vaultRandomID ); - // log.info(prevSyncEntityList); + log.debug(prevSyncEntityList); if (this.settings.currLogLevel === "info") { // pass diff --git a/src/misc.ts b/src/misc.ts index 69b0122..eaa0e88 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -76,17 +76,16 @@ export const getFolderLevels = (x: string, addEndingSlash: boolean = false) => { export const mkdirpInVault = async (thePath: string, vault: Vault) => { // log.info(thePath); - - // as of 2020219, - // Obsidian can create the folder recursively - // but the path should not end with '/' - if (thePath === "/" || thePath === "") { - return; + const foldersToBuild = getFolderLevels(thePath); + // log.info(foldersToBuild); + for (const folder of foldersToBuild) { + const r = await vault.adapter.exists(folder); + // log.info(r); + if (!r) { + log.info(`mkdir ${folder}`); + await vault.adapter.mkdir(folder); + } } - let thePathNoEnding = thePath.endsWith("/") - ? thePath.slice(0, thePath.length - 1) - : thePath; - await vault.adapter.mkdir(thePathNoEnding); }; /** diff --git a/src/sync.ts b/src/sync.ts index 7693d14..cff90a6 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -442,6 +442,8 @@ export const getSyncPlanInplace = async ( // folder // folder doesn't worry about mtime and size, only check their existences if (keptFolder.has(key)) { + // parent should also be kept + keptFolder.add(getParentFolder(key)); // should fill the missing part if (local !== undefined && remote !== undefined) { mixedEntry.decisionBranch = 101; @@ -731,7 +733,9 @@ const splitThreeStepsOnEntityMappings = ( val.decision === "folder_existed_remote" || val.decision === "folder_to_be_created" ) { + log.debug(`splitting folder: key=${key},val=${JSON.stringify(val)}`); const level = atWhichLevel(key); + log.debug(`atWhichLevel: ${level}`); if (folderCreationOps[level - 1] === undefined) { folderCreationOps[level - 1] = [val]; } else { @@ -891,6 +895,11 @@ export const doActualSync = async ( log.debug(`concurrency === ${concurrency}`); const { folderCreationOps, deletionOps, uploadDownloads, realTotalCount } = splitThreeStepsOnEntityMappings(mixedEntityMappings); + log.debug(`folderCreationOps: ${JSON.stringify(folderCreationOps)}`); + log.debug(`deletionOps: ${JSON.stringify(deletionOps)}`); + log.debug(`uploadDownloads: ${JSON.stringify(uploadDownloads)}`); + log.debug(`realTotalCount: ${JSON.stringify(realTotalCount)}`); + const nested = [folderCreationOps, deletionOps, uploadDownloads]; const logTexts = [ `1. create all folders from shadowest to deepest, also check undefined decision`,