Squashed commit of sync hidden files:

commit 73967756d51d246b3ca203aa3683cdfebf567000
Author: fyears <1142836+fyears@users.noreply.github.com>
Date:   Sun Mar 13 22:41:28 2022 +0800

    fix typo

commit 08e16faa9a9ace9bec71acb723e0d70ca361d49f
Author: fyears <1142836+fyears@users.noreply.github.com>
Date:   Sun Mar 13 22:41:01 2022 +0800

    add modal in settings

commit 9db7194fa28cb62b1fa4c01ac7f746d5ac3b86a8
Author: fyears <1142836+fyears@users.noreply.github.com>
Date:   Sun Mar 13 22:03:00 2022 +0800

    working sync for .obsidian and _

commit 4be24ba092181c1c3e1aabe5e9d4e9fcff28f987
Author: fyears <1142836+fyears@users.noreply.github.com>
Date:   Sun Mar 13 16:07:10 2022 +0800

    more logic for hidden path
This commit is contained in:
fyears
2022-03-13 22:42:16 +08:00
parent 0b5b9cf51a
commit af93af9047
8 changed files with 380 additions and 38 deletions
+63 -5
View File
@@ -46,6 +46,7 @@ import {
import * as origLog from "loglevel";
import { padEnd } from "lodash";
import { isInsideObsFolder, ObsConfigDirFileType } from "./obsFolderLister";
const log = origLog.getLogger("rs-default");
export type SyncStatusType =
@@ -272,18 +273,39 @@ export const fetchMetadataFile = async (
return metadata;
};
const isSkipItem = (
key: string,
syncConfigDir: boolean,
syncUnderscoreItems: boolean,
configDir: string
) => {
if (syncConfigDir && isInsideObsFolder(key, configDir)) {
return false;
}
return (
isHiddenPath(key, true, false) ||
(!syncUnderscoreItems && isHiddenPath(key, false, true)) ||
key === DEFAULT_FILE_NAME_FOR_METADATAONREMOTE ||
key === DEFAULT_FILE_NAME_FOR_METADATAONREMOTE2
);
};
const ensembleMixedStates = async (
remoteStates: FileOrFolderMixedState[],
local: TAbstractFile[],
localConfigDirContents: ObsConfigDirFileType[] | undefined,
remoteDeleteHistory: DeletionOnRemote[],
localDeleteHistory: FileFolderHistoryRecord[]
localDeleteHistory: FileFolderHistoryRecord[],
syncConfigDir: boolean,
configDir: string,
syncUnderscoreItems: boolean
) => {
const results = {} as Record<string, FileOrFolderMixedState>;
for (const r of remoteStates) {
const key = r.key;
if (isHiddenPath(key)) {
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
continue;
}
results[key] = r;
@@ -316,9 +338,10 @@ const ensembleMixedStates = async (
throw Error(`unexpected ${entry}`);
}
if (isHiddenPath(key)) {
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
continue;
}
if (results.hasOwnProperty(key)) {
results[key].key = r.key;
results[key].existLocal = r.existLocal;
@@ -330,6 +353,28 @@ const ensembleMixedStates = async (
}
}
if (syncConfigDir && localConfigDirContents !== undefined) {
for (const entry of localConfigDirContents) {
const key = entry.key;
const r: FileOrFolderMixedState = {
key: key,
existLocal: true,
mtimeLocal: Math.max(entry.mtime, entry.ctime),
sizeLocal: entry.size,
};
if (results.hasOwnProperty(key)) {
results[key].key = r.key;
results[key].existLocal = r.existLocal;
results[key].mtimeLocal = r.mtimeLocal;
results[key].sizeLocal = r.sizeLocal;
} else {
results[key] = r;
results[key].existRemote = false;
}
}
}
for (const entry of remoteDeleteHistory) {
const key = entry.key;
const r = {
@@ -337,6 +382,10 @@ const ensembleMixedStates = async (
deltimeRemote: entry.actionWhen,
} as FileOrFolderMixedState;
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
continue;
}
if (results.hasOwnProperty(key)) {
results[key].key = r.key;
results[key].deltimeRemote = r.deltimeRemote;
@@ -365,9 +414,10 @@ const ensembleMixedStates = async (
deltimeLocal: entry.actionWhen,
} as FileOrFolderMixedState;
if (isHiddenPath(key)) {
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
continue;
}
if (results.hasOwnProperty(key)) {
results[key].key = r.key;
results[key].deltimeLocal = r.deltimeLocal;
@@ -618,17 +668,25 @@ const DELETION_DECISIONS: Set<DecisionType> = new Set([
export const getSyncPlan = async (
remoteStates: FileOrFolderMixedState[],
local: TAbstractFile[],
localConfigDirContents: ObsConfigDirFileType[] | undefined,
remoteDeleteHistory: DeletionOnRemote[],
localDeleteHistory: FileFolderHistoryRecord[],
remoteType: SUPPORTED_SERVICES_TYPE,
vault: Vault,
syncConfigDir: boolean,
configDir: string,
syncUnderscoreItems: boolean,
password: string = ""
) => {
const mixedStates = await ensembleMixedStates(
remoteStates,
local,
localConfigDirContents,
remoteDeleteHistory,
localDeleteHistory
localDeleteHistory,
syncConfigDir,
configDir,
syncUnderscoreItems
);
const sortedKeys = Object.keys(mixedStates).sort(