Skip to content

Commit

Permalink
add new line
Browse files Browse the repository at this point in the history
  • Loading branch information
s-dwinter committed Jun 2, 2024
1 parent 8d67413 commit 934f07a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
17 changes: 12 additions & 5 deletions internal/client/cache/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ func (f *fileCache) Load(_ context.Context, key string, decrypt bool) (*string,
// check if cache is expired
expired := time.Since(fInfo.ModTime().Local()) > f.expireDuration

cacheByte, err := f.readFile(filename, false)
valueByte, err := f.readFile(filename, false)
if err != nil {
return nil, false, err
}
if !decrypt {
cache := string(cacheByte)
return &cache, expired, nil
value := string(valueByte)
return &value, expired, nil
}

valueByte, err := f.decryptCache(cacheByte)
valueByte, err = f.decryptCache(valueByte)
if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -226,7 +226,13 @@ func (f fileCache) readFile(filename string, hidden bool) ([]byte, error) {
filename = "." + filename
}

return os.ReadFile(filepath.Join(f.cachePath, filename))
data, err := os.ReadFile(filepath.Join(f.cachePath, filename))
if err != nil {
return nil, err
}
data = data[:len(data)-1]

return data, nil
}

func (f fileCache) writeToFile(filename string, data []byte, hidden bool) error {
Expand All @@ -241,6 +247,7 @@ func (f fileCache) writeToFile(filename string, data []byte, hidden bool) error
}
defer file.Close()

data = append(data, '\n')
if _, err := file.Write(data); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/cache/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func Test_fileCache_SaveAndLoad(t *testing.T) {
t.Errorf("fileCache.Load() expired = %v, want %v", gotExpired, tt.wantExpired)
}
if !reflect.DeepEqual(gotValue, tt.args.value) {
t.Errorf("fileCache.Load() got = %v, want %v", gotValue, tt.args.value)
t.Errorf("fileCache.Load() got = %v, want %v", *gotValue, *tt.args.value)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wBs)�\�.<����e��!*���`XS`
�{��s��>}��W[2�6�ot�k�
Original file line number Diff line number Diff line change
@@ -1 +1 @@
expired-value
expired-value
Original file line number Diff line number Diff line change
@@ -1 +1 @@
plain-value
plain-value
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prefix-value
prefix-value

0 comments on commit 934f07a

Please sign in to comment.