Skip to content

Commit

Permalink
Fix contentcache error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thepenguinco authored and lezh committed Mar 30, 2022
1 parent 51a39f4 commit 8a18ae4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions internal/contentcache/contentcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ func (c *ContentCache) recoverFileFromCache(metadataFile fs.FileInfo) {
}

// RecoverCache recovers the cache with existing persisted files when gcsfuse starts
//
// RecoverCache should not be called concurrently
func (c *ContentCache) RecoverCache() error {
if c.tempDir == "" {
Expand Down Expand Up @@ -202,12 +201,9 @@ func (c *ContentCache) AddOrReplace(cacheObjectKey *CacheObjectKey, generation i
// Create a temporary cache file on disk
f, err := ioutil.TempFile(c.tempDir, CacheFilePrefix)
if err != nil {
err = fmt.Errorf("TempFile: %w", err)
}
file, err := c.NewCacheFile(rc, f)
if err != nil {
return nil, fmt.Errorf("NewCacheFile: %w", err)
return nil, fmt.Errorf("TempFile: %w", err)
}
file := c.NewCacheFile(rc, f)
metadata := &CacheFileObjectMetadata{
CacheFileNameOnDisk: file.Name(),
BucketName: cacheObjectKey.BucketName,
Expand Down Expand Up @@ -249,8 +245,8 @@ func (c *ContentCache) Remove(cacheObjectKey *CacheObjectKey) {
}
}

// NewCacheFile creates a cache file on the disk storing the object content
func (c *ContentCache) NewCacheFile(rc io.ReadCloser, f *os.File) (gcsx.TempFile, error) {
// NewCacheFile returns a cache tempfile wrapper around the source reader and file
func (c *ContentCache) NewCacheFile(rc io.ReadCloser, f *os.File) gcsx.TempFile {
return gcsx.NewCacheFile(rc, f, c.tempDir, c.mtimeClock)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/fs/inode/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (f *FileInode) ensureContent(ctx context.Context) (err error) {

rc, err := f.openReader(ctx)
if err != nil {
fmt.Errorf("open reader error: %w", err)
err = fmt.Errorf("openReader Error: %w", err)
return err
}

Expand All @@ -231,7 +231,7 @@ func (f *FileInode) ensureContent(ctx context.Context) (err error) {

rc, err := f.openReader(ctx)
if err != nil {
fmt.Errorf("Open Reader Error: %w", err)
err = fmt.Errorf("openReader Error: %w", err)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions internal/gcsx/temp_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ func NewTempFile(
return
}

// NewCacheFile creates a temp file whose initial contents are given by the
// supplied reader. dir is a directory on whose file system the file will live,
// NewCacheFile creates a wrapper temp file whose initial contents are given by the
// supplied source. dir is a directory on whose file system the file will live,
// or the system default temporary location if empty.
func NewCacheFile(
source io.ReadCloser,
f *os.File,
dir string,
clock timeutil.Clock) (tf TempFile, err error) {
clock timeutil.Clock) (tf TempFile) {

tf = &tempFile{
source: source,
Expand Down

0 comments on commit 8a18ae4

Please sign in to comment.