diff --git a/common/common.go b/common/common.go index 8737eb2..e081ed2 100644 --- a/common/common.go +++ b/common/common.go @@ -6,6 +6,8 @@ import ( "mime/multipart" "net/http" "os" + "path" + "strings" "time" "git.cheetah.cat/worksucc/gma-puzzles/gma" @@ -19,6 +21,8 @@ type DB_GMA struct { ProcessingEnd time.Time `json:"processingEnd"` ProcessingDuration int64 `json:"processingDuration"` + MigrationID string `json:"migrationID"` + OriginalPath string `json:"originalPath"` StatModTime time.Time `json:"statModTime"` GMASize int64 `json:"archiveSize"` @@ -31,9 +35,10 @@ type DB_GMA struct { RetryCounter int `json:"retries"` } type DB_GMA_Alias struct { - Path string `json:"path"` - Hash string `json:"hash"` - Deleted bool `json:"deleted"` + MigrationID string `json:"migrationID"` + Path string `json:"path"` + Hash string `json:"hash"` + Deleted bool `json:"deleted"` } type DB_GMADeletionData struct { Deleted bool `json:"deleted"` @@ -222,3 +227,7 @@ func (s *semaphore) Release() { func (s *semaphore) Close() { close(s.semC) } + +func CreateMigrationID(filePath string) string { + return strings.ReplaceAll(strings.ReplaceAll(path.Base(filePath), ".gma", ""), ".", "_") +} diff --git a/main.go b/main.go index 5848f5f..b9ce15d 100644 --- a/main.go +++ b/main.go @@ -619,6 +619,7 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) { if dboGMA_sameHash.OriginalPath != filePath { pw.Log("originalpath differs for this hash") // DB_GMA_Alias + dboGMA.OriginalPath = dboGMA_sameHash.OriginalPath } } if dboGMA.OriginalPath == filePath { @@ -657,21 +658,20 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) { return fmt.Errorf("650-: %v", err) } if originalDeletionData.Deleted { + pw.Log(filepath.Base(filePath)) + pw.Log(filepath.Base(dboGMA_sameHash.OriginalPath)) + pw.Log("") aliasData := common.DB_GMA_Alias{ - Path: filePath, - Hash: dboGMA.GMAHash, - Deleted: true, + Path: filePath, + Hash: dboGMA.GMAHash, + Deleted: true, + MigrationID: common.CreateMigrationID(filePath), } - recoveryPath := filepath.Join("/zpool0/cheetah/workshop/garrysmod/gma-inator/recovery-tree", fmt.Sprintf("%s.json", dboGMA.OriginalPath)) - if checkFileExists(recoveryPath) { - err = os.Remove(aliasData.Path) - if err != nil { - return err - } - pw.Log("deleted %s duplicate, original was %s", aliasData.Path, dboGMA.OriginalPath) - } else { - pw.Log("%s recoveryPath does not exist %s", filePath, recoveryPath) + err = os.Remove(aliasData.Path) + if err != nil { + return err } + pw.Log("deleted %s", aliasData.Path) lzmaFile := fmt.Sprintf("%s.lzma", aliasData.Path) if checkFileExists(lzmaFile) { err = os.Remove(lzmaFile) @@ -680,7 +680,10 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) { } pw.Log("deleted %s", lzmaFile) } - _, _ = colAliases.CreateDocument(arangoCTX, aliasData) + _, err = colAliases.CreateDocument(arangoCTX, aliasData) + if err != nil { + return err + } } else { return fmt.Errorf("originals have not been deleted") } @@ -1208,6 +1211,7 @@ func ProcessGMA(pw progress.Writer, filePath string) (err error) { dboGMA.ProcessingEnd = time.Now() dboGMA.ProcessingDuration = dboGMA.ProcessingEnd.Sub(dboGMA.ProcessingStart).Milliseconds() dboGMA.Success = true + dboGMA.MigrationID = common.CreateMigrationID(dboGMA.OriginalPath) _, err = colGMA.UpdateDocument(arangoCTX, dboGMA.ID, dboGMA) if err != nil {