Add justDownloaded field in files metadata

This commit is contained in:
Silvano Cerza 2025-01-09 14:35:40 +01:00
parent 4e5308bc07
commit 509b41fb57
3 changed files with 27 additions and 0 deletions

View file

@ -33,11 +33,23 @@ export default class EventsListener {
// The file has not been created in directory that we're syncing with GitHub
return;
}
const data = this.metadataStore.data[file.path];
if (data && data.justDownloaded) {
// This file was just downloaded and not created by the user.
// It's enough to makr it as non just downloaded.
this.metadataStore.data[file.path].justDownloaded = false;
await this.metadataStore.save();
return;
}
this.metadataStore.data[file.path] = {
localPath: file.path,
remotePath: file.path.replace(this.localContentDir, this.repoContentDir),
sha: null,
dirty: true,
// This file has been created by the user
justDownloaded: false,
};
await this.metadataStore.save();
this.eventsQueue.enqueue({
@ -64,6 +76,15 @@ export default class EventsListener {
// The file has not been create in directory that we're syncing with GitHub
return;
}
const data = this.metadataStore.data[file.path];
if (data && data.justDownloaded) {
// This file was just downloaded and not modified by the user.
// It's enough to makr it as non just downloaded.
this.metadataStore.data[file.path].justDownloaded = false;
await this.metadataStore.save();
return;
}
this.metadataStore.data[file.path].dirty = true;
await this.metadataStore.save();
this.eventsQueue.enqueue({

View file

@ -77,6 +77,7 @@ export default class GithubClient {
remotePath: file.path,
sha: file.sha,
dirty: false,
justDownloaded: true,
};
await this.metadataStore.save();
}),

View file

@ -15,6 +15,11 @@ export interface FileMetadata {
sha: string | null;
// Whether the file has been modified locally.
dirty: boolean;
// This is mostly used to track if the file has been just downloaded from the remote.
// This is necessary since even when creating a file programatically after it has been
// downloaded it will trigger a 'create' or 'modify' event.
// This is a problem as we can't know whether an event has been triggered by us or the user.
justDownloaded: boolean;
}
export interface Metadata {