Skip to content

Commit

Permalink
fix: ensure ranges/keys are always uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLoch committed Feb 16, 2024
1 parent 4dfe0b3 commit 86d9c9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func run(dataDir string) error {
return fmt.Errorf("syncing: %w", err)
}

// Explicitly close the file because otherwise we cannot remove it
stateFile.Close()

if err := os.Remove(stateFilePath); err != nil {
return fmt.Errorf("removing state file %q: %w", stateFilePath, err)
}
Expand Down
7 changes: 7 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"path"
"strings"
syncPkg "sync"
)

Expand Down Expand Up @@ -73,6 +74,8 @@ func (f *fsStorage) lockFile(key string, t lockType) func() {
}

func (f *fsStorage) Save(key, etag string, data []byte) error {
key = strings.ToUpper(key)

defer f.lockFile(key, write)()

if err := f.createDirs(key); err != nil {
Expand Down Expand Up @@ -124,6 +127,8 @@ func (f *fsStorage) createDirs(key string) error {
}

func (f *fsStorage) LoadETag(key string) (string, error) {
key = strings.ToUpper(key)

defer f.lockFile(key, read)()

file, err := os.Open(f.filePath(key))
Expand Down Expand Up @@ -154,6 +159,8 @@ func (f *fsStorage) LoadETag(key string) (string, error) {
}

func (f *fsStorage) LoadData(key string) (io.ReadCloser, error) {
key = strings.ToUpper(key)

unlockFile := f.lockFile(key, read)

file, err := os.Open(f.filePath(key))
Expand Down

0 comments on commit 86d9c9b

Please sign in to comment.