@@ -39,8 +39,7 @@ export default class SyncManager {
3939 this . eventsListener = new EventsListener (
4040 this . vault ,
4141 this . metadataStore ,
42- this . settings . localContentDir ,
43- this . settings . repoContentDir ,
42+ this . settings ,
4443 ) ;
4544 }
4645
@@ -660,6 +659,71 @@ export default class SyncManager {
660659 }
661660 }
662661
662+ /**
663+ * Add all the files in the config dir in the metadata store.
664+ * This is mainly useful when the user changes the sync config settings
665+ * as we need to add those files to the metadata store or they would never be synced.
666+ */
667+ async addConfigDirToMetadata ( ) {
668+ // Get all the files in the config dir
669+ let files = [ ] ;
670+ let folders = [ this . vault . configDir ] ;
671+ while ( folders . length > 0 ) {
672+ const folder = folders . pop ( ) ;
673+ if ( folder === undefined ) {
674+ continue ;
675+ }
676+ const res = await this . vault . adapter . list ( folder ) ;
677+ files . push ( ...res . files ) ;
678+ folders . push ( ...res . folders ) ;
679+ }
680+ // Add them to the metadata store
681+ files . forEach ( ( filePath : string ) => {
682+ this . metadataStore . data . files [ filePath ] = {
683+ localPath : filePath ,
684+ // Remote path is the same for config dir files
685+ remotePath : filePath ,
686+ sha : null ,
687+ dirty : false ,
688+ justDownloaded : false ,
689+ lastModified : Date . now ( ) ,
690+ } ;
691+ } ) ;
692+ this . metadataStore . save ( ) ;
693+ }
694+
695+ /**
696+ * Remove all the files in the config dir from the metadata store.
697+ * The metadata file is not removed as it must always be present.
698+ * This is mainly useful when the user changes the sync config settings
699+ * as we need to remove those files to the metadata store or they would
700+ * keep being synced.
701+ */
702+ async removeConfigDirFromMetadata ( ) {
703+ // Get all the files in the config dir
704+ let files = [ ] ;
705+ let folders = [ this . vault . configDir ] ;
706+ while ( folders . length > 0 ) {
707+ const folder = folders . pop ( ) ;
708+ if ( folder === undefined ) {
709+ continue ;
710+ }
711+ const res = await this . vault . adapter . list ( folder ) ;
712+ files . push ( ...res . files ) ;
713+ folders . push ( ...res . folders ) ;
714+ }
715+
716+ // Remove all them from the metadata store
717+ files . forEach ( ( filePath : string ) => {
718+ if ( filePath === `${ this . vault . configDir } /github-sync-metadata.json` ) {
719+ // We don't want to remove the metadata file even if it's in the config dir
720+ return ;
721+ }
722+ delete this . metadataStore . data . files [ filePath ] ;
723+ } ) ;
724+ this . metadataStore . save ( ) ;
725+ }
726+
663727 getFileMetadata ( filePath : string ) : FileMetadata {
664728 return this . metadataStore . data . files [ filePath ] ;
665729 }
0 commit comments