This commit is contained in:
2025-09-02 19:21:03 +02:00
parent 7bf88d9d8c
commit fdc019a200
9 changed files with 94 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
package constants
const Version = "0.0.4c"
const Version = "0.0.5"
const ApiVersion = 1

View File

@@ -252,6 +252,12 @@ func (l Service) PullCurrent(id, path string, cli *client.Client) error {
return fmt.Errorf("failed to open blob from local repository: %w", err)
}
if _, err := os.Stat(path); err == nil {
if err := os.RemoveAll(path); err != nil {
return fmt.Errorf("failed to clean the destination directory: %w", err)
}
}
if err := os.MkdirAll(path, 0740); err != nil {
return fmt.Errorf("failed to create destination directory: %w", err)
}

View File

@@ -224,6 +224,11 @@ func (c *Client) Pull(gameID, archivePath string) error {
if err != nil {
return fmt.Errorf("failed to open file: %w", err)
}
defer func() {
if err := os.Rename(archivePath+".part", archivePath); err != nil {
panic(err)
}
}()
defer f.Close()
res, err := cli.Do(req)
@@ -246,8 +251,10 @@ func (c *Client) Pull(gameID, archivePath string) error {
return fmt.Errorf("an error occured while copying the file from the remote: %w", err)
}
if err := os.Rename(archivePath+".part", archivePath); err != nil {
return fmt.Errorf("failed to move temporary data: %w", err)
if err := os.Remove(archivePath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("failed to remove the old version of the archive: %w", err)
}
}
return nil

View File

@@ -73,7 +73,7 @@ type (
AllHist(gameID GameIdentifier) ([]string, error)
WriteBlob(ID Identifier) (io.Writer, error)
WriteMetadata(gameID GameIdentifier, m Metadata) error
WriteMetadata(gameID GameIdentifier, m Metadata) error
Metadata(gameID GameIdentifier) (Metadata, error)
LastScan(gameID GameIdentifier) (time.Time, error)