diff --git a/lzmafix.sh b/lzmafix.sh new file mode 100644 index 0000000..c2dfe80 --- /dev/null +++ b/lzmafix.sh @@ -0,0 +1,39 @@ +#!/bin/bash +checkGMAD() { + header=$(head -c4 $1 | xxd -ps) + echo "'$header'" + if [[ "$header" = "474d4144" ]]; then + return 0 + else + return 1 + fi +} + +checkLZMA() { + header=$(cat $1 | lzma -d - | head -c4 | xxd -ps) + if [[ "$header" = "474d4144" ]]; then + return 0 + else + return 1 + fi +} + +testNfix() { + file=$1 + if checkGMAD "$file"; then + echo "file is native GMAD" + else + if checkLZMA "$file"; then + echo "file is lzma'd GMAD" + cat "$file" | lzma -d > "$file.unc" + if checkGMAD "$file.unc"; then + mv "$file" "$file.lzma" && mv "$file.unc" "$file" && echo "file has been converted to GMAD" && exit 0 + else + echo "file couldn't be converted" + fi + rm "$file.unc" + else + echo "file is somewhat else" + fi + fi +} diff --git a/main.go b/main.go index 18a1290..5184603 100644 --- a/main.go +++ b/main.go @@ -292,7 +292,7 @@ func modeRebuild(id string) (err error) { for _, dboGMA2File := range dboGMA2Files { //fmt.Printf("WriteFile for %s number %d = %s\n", dboGMA2File.FileName, dboGMA2File.FileNumber, dboGMA2File.UploadID) - resp, err := httpClient.Get(fmt.Sprintf("http://127.0.0.1:13371/fetch/%s", dboGMA2File.UploadID)) + resp, err := httpClient.Get(fmt.Sprintf("http://192.168.133.118:13371/fetch/%s", dboGMA2File.UploadID)) if err != nil { return err } @@ -344,8 +344,11 @@ func recursive(jobs []string, folderPath string) (WorkerJobPool []string) { if e.IsDir() { jobs = recursive(jobs, fullPath) } - if !e.IsDir() { - jobs = append(jobs, filepath.Join(folderPath, e.Name())) + fmt.Println(e.Name()) + if strings.HasSuffix(e.Name(), ".gma") && !strings.Contains(e.Name(), ".lzma") { + if !e.IsDir() { + jobs = append(jobs, filepath.Join(folderPath, e.Name())) + } } } return jobs @@ -364,8 +367,11 @@ func modeDelete(folderPath string) { if e.IsDir() { WorkerJobPool = recursive(WorkerJobPool, fullPath) } - if !e.IsDir() { - WorkerJobPool = append(WorkerJobPool, filepath.Join(folderPath, e.Name())) + fmt.Println(e.Name()) + if strings.HasSuffix(e.Name(), ".gma") && !strings.Contains(e.Name(), ".lzma") { + if !e.IsDir() { + WorkerJobPool = append(WorkerJobPool, filepath.Join(folderPath, e.Name())) + } } } wg := sync.WaitGroup{} @@ -432,8 +438,11 @@ func modeIngress(folderPath string, skipN int) { if e.IsDir() { WorkerJobPool = recursive(WorkerJobPool, fullPath) } - if !e.IsDir() { - WorkerJobPool = append(WorkerJobPool, filepath.Join(folderPath, e.Name())) + fmt.Println(e.Name()) + if strings.HasSuffix(e.Name(), ".gma") && !strings.Contains(e.Name(), ".lzma") { + if !e.IsDir() { + WorkerJobPool = append(WorkerJobPool, filepath.Join(folderPath, e.Name())) + } } } if skipN > 0 { @@ -557,11 +566,11 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) { if dboGMA.GMASize < 200 { return fmt.Errorf("GMA File too small, skipping") } - niceName := filepath.Base(filePath) - trackerProcessDoneMarker := sync.Once{} - trackerProcess := progress.Tracker{Message: fmt.Sprintf("Deleting %s", niceName), Total: 0, Units: progress.UnitsDefault} - defer trackerProcessDoneMarker.Do(trackerProcess.MarkAsDone) - pw.AppendTracker(&trackerProcess) + //niceName := filepath.Base(filePath) + //trackerProcessDoneMarker := sync.Once{} + //trackerProcess := progress.Tracker{Message: fmt.Sprintf("Deleting %s", niceName), Total: 0, Units: progress.UnitsDefault} + //defer trackerProcessDoneMarker.Do(trackerProcess.MarkAsDone) + //pw.AppendTracker(&trackerProcess) gmaReader, err := gma.NewReader(filePath) if err != nil { @@ -591,7 +600,15 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) { if err != nil { return err } - fmt.Printf("would delete %s\n", dboGMA.OriginalPath) + pw.Log("deleted %s", dboGMA.OriginalPath) + } + lzmaFile := fmt.Sprintf("%s.lzma", dboGMA.OriginalPath) + if checkFileExists(lzmaFile) { + err = os.Remove(lzmaFile) + if err != nil { + return err + } + pw.Log("deleted %s", lzmaFile) } } _, err = colGMA.UpdateDocument(arangoCTX, dboGMA.ID, common.DB_GMADeletionData{ @@ -855,7 +872,7 @@ func ProcessGMA(pw progress.Writer, filePath string) (err error) { //dboFile2ChunkID := fmt.Sprintf("file_chunk_map/%s", dboFile.ID) // TODO: Check against Storage backend - res, err := http.Get(fmt.Sprintf("http://127.0.0.1:13371/check/%s", dboFile.ID)) + res, err := http.Get(fmt.Sprintf("http://192.168.133.118:13371/check/%s", dboFile.ID)) if err != nil { return err } @@ -912,7 +929,7 @@ func ProcessGMA(pw progress.Writer, filePath string) (err error) { //uploadBar.Describe("Uploading") trackerUpload.UpdateMessage(fmt.Sprintf("Uploading %s", niceName)) - err = common.MultipartUpload(httpClient, fmt.Sprintf("http://127.0.0.1:13371/stash/%s/%d", dboGMA2File.UploadID, dboGMA2File.FileSize), dboGMA2File.LocalFileName, fileInfoJSON, workerID) + err = common.MultipartUpload(httpClient, fmt.Sprintf("http://192.168.133.118:13371/stash/%s/%d", dboGMA2File.UploadID, dboGMA2File.FileSize), dboGMA2File.LocalFileName, fileInfoJSON, workerID) if err != nil { log.Println("err @common.MultipartUpload") log.Println(err) @@ -1042,7 +1059,7 @@ func ProcessGMA(pw progress.Writer, filePath string) (err error) { for _, dboGMA2File := range rw_dboGMA2Files { //fmt.Printf("WriteFile for %s number %d = %s\n", dboGMA2File.FileName, dboGMA2File.FileNumber, dboGMA2File.UploadID) - resp, err := httpClient.Get(fmt.Sprintf("http://127.0.0.1:13371/fetch/%s", dboGMA2File.UploadID)) + resp, err := httpClient.Get(fmt.Sprintf("http://192.168.133.118:13371/fetch/%s", dboGMA2File.UploadID)) if err != nil { undoBatch(true, dboGMA.ID, fileIDs, gma2FileIDs) return err diff --git a/storageserver/storageserver.go b/storageserver/storageserver.go index 50c6deb..edcee1d 100644 --- a/storageserver/storageserver.go +++ b/storageserver/storageserver.go @@ -38,7 +38,6 @@ var ( PoolPathTemp = "/zpool0/cheetah/workshop/garrysmod/gma-inator/temp" ) -// TODO: write Recovery Data after Packing type PoolRecoveryData struct { PoolID string `json:"_key"` Size uint64 `json:"size"`