Skip to content

Commit 41b1c6e

Browse files
committed
feat(conflict): Remove conflict files before syncing.
1 parent 3af1ba6 commit 41b1c6e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/main.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ export default class InvioPlugin extends Plugin {
155155
if (file.extension !== 'md') {
156156
return false;
157157
}
158+
if (file.path.endsWith('.conflict.md')) {
159+
return false;
160+
}
161+
if (file.path.split('/')[1] === RemoteConflictPrefix) {
162+
return false;
163+
}
164+
if (file.path.split('/')[1] === LocalConflictPrefix) {
165+
return false;
166+
}
158167
return true;
159168
};
160169

@@ -176,22 +185,27 @@ export default class InvioPlugin extends Plugin {
176185
}
177186

178187
async getLocalFileStatus() {
188+
const isWatched = (p: string) => {
189+
const pF = new Path(p)
190+
pF.isInsideDir(this.settings.localWatchDir) &&
191+
!pF.isInsideDir(RemoteConflictPrefix) &&
192+
!pF.isInsideDir(LocalConflictPrefix) &&
193+
!p.endsWith('.conflict.md')
194+
}
179195
// this.app.vault.getAllLoadedFiles
180196
// TODO: List only concerned files, only source of truth
181197
// *.conflict.md files is for data backup when conflicts happened
182198
const local = this.app.vault.getMarkdownFiles().filter(file => {
183-
const p = new Path(file.path);
184-
return p.isInsideDir(this.settings.localWatchDir) &&
185-
!p.isInsideDir(RemoteConflictPrefix) &&
186-
!p.isInsideDir(LocalConflictPrefix) &&
187-
!file.path.endsWith('.conflict.md')
199+
return isWatched(file.path)
188200
});
189201
log.info('local file path list: ', local);
190202
// const local = this.app.vault.getAllLoadedFiles();
191-
const localHistory = await loadFileHistoryTableByVault(
203+
const localHistory = (await loadFileHistoryTableByVault(
192204
this.db,
193205
this.vaultRandomID
194-
);
206+
)).filter(item => {
207+
return isWatched(item.key)
208+
})
195209
let localConfigDirContents: ObsConfigDirFileType[] = undefined;
196210
if (this.settings.syncConfigDir) {
197211
localConfigDirContents = await listFilesInObsFolder(

0 commit comments

Comments
 (0)