sync: Add Init and Sync functions
Init initializes the directory/repository before the first use. Sync is called to unsure the directory is up-to-date.
This commit is contained in:
parent
281056a723
commit
aebfb7bf96
7 changed files with 62 additions and 6 deletions
|
|
@ -22,6 +22,11 @@ var oneThemeDeepSync sync.Mutex
|
|||
// DeepSyncProgress expose the progression of the depp synchronization (0 = 0%, 255 = 100%).
|
||||
var DeepSyncProgress uint8
|
||||
|
||||
// avoidImporterSync checks if Sync should be called or not.
|
||||
func avoidImporterSync() bool {
|
||||
return DeepSyncProgress > 1 && DeepSyncProgress < 255
|
||||
}
|
||||
|
||||
// SpeedySyncDeep performs a recursive synchronisation without importing files.
|
||||
func SpeedySyncDeep(i Importer) (errs map[string][]string) {
|
||||
oneDeepSync.Lock()
|
||||
|
|
@ -36,6 +41,11 @@ func SpeedySyncDeep(i Importer) (errs map[string][]string) {
|
|||
errs = map[string][]string{}
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
if err := i.Sync(); err != nil {
|
||||
errs["_sync"] = []string{err.Error()}
|
||||
}
|
||||
|
||||
errs["_date"] = []string{fmt.Sprintf("%v", startTime)}
|
||||
errs["_themes"] = SyncThemes(i)
|
||||
|
||||
|
|
@ -89,6 +99,11 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
|||
errs = map[string][]string{}
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
if err := i.Sync(); err != nil {
|
||||
errs["_sync"] = []string{err.Error()}
|
||||
}
|
||||
|
||||
errs["_date"] = []string{fmt.Sprintf("%v", startTime)}
|
||||
errs["_themes"] = SyncThemes(i)
|
||||
|
||||
|
|
@ -171,6 +186,10 @@ func SyncThemeDeep(i Importer, theme fic.Theme, tid int, themeStep uint8) (errs
|
|||
oneThemeDeepSync.Lock()
|
||||
defer oneThemeDeepSync.Unlock()
|
||||
|
||||
if err := i.Sync(); err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
}
|
||||
|
||||
DeepSyncProgress = 3 + uint8(tid)*themeStep
|
||||
errs = SyncExercices(i, theme)
|
||||
|
||||
|
|
|
|||
Reference in a new issue