Skip to content

Commit

Permalink
Merge pull request #332 from pojntfx/master
Browse files Browse the repository at this point in the history
Call `OpenFile` instead of `Open` in `CacheOnReadFs` (fixes #193)
  • Loading branch information
0xmichalis committed Jan 5, 2022
2 parents 8298014 + 039e386 commit cd35605
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 5 additions & 1 deletion cacheOnReadFs.go
Expand Up @@ -75,6 +75,10 @@ func (u *CacheOnReadFs) copyToLayer(name string) error {
return copyToLayer(u.base, u.layer, name)
}

func (u *CacheOnReadFs) copyFileToLayer(name string, flag int, perm os.FileMode) error {
return copyFileToLayer(u.base, u.layer, name, flag, perm)
}

func (u *CacheOnReadFs) Chtimes(name string, atime, mtime time.Time) error {
st, _, err := u.cacheStatus(name)
if err != nil {
Expand Down Expand Up @@ -212,7 +216,7 @@ func (u *CacheOnReadFs) OpenFile(name string, flag int, perm os.FileMode) (File,
switch st {
case cacheLocal, cacheHit:
default:
if err := u.copyToLayer(name); err != nil {
if err := u.copyFileToLayer(name, flag, perm); err != nil {
return nil, err
}
}
Expand Down
28 changes: 21 additions & 7 deletions unionFile.go
Expand Up @@ -268,13 +268,7 @@ func (f *UnionFile) WriteString(s string) (n int, err error) {
return 0, BADFD
}

func copyToLayer(base Fs, layer Fs, name string) error {
bfh, err := base.Open(name)
if err != nil {
return err
}
defer bfh.Close()

func copyFile(base Fs, layer Fs, name string, bfh File) error {
// First make sure the directory exists
exists, err := Exists(layer, filepath.Dir(name))
if err != nil {
Expand Down Expand Up @@ -315,3 +309,23 @@ func copyToLayer(base Fs, layer Fs, name string) error {
}
return layer.Chtimes(name, bfi.ModTime(), bfi.ModTime())
}

func copyToLayer(base Fs, layer Fs, name string) error {
bfh, err := base.Open(name)
if err != nil {
return err
}
defer bfh.Close()

return copyFile(base, layer, name, bfh)
}

func copyFileToLayer(base Fs, layer Fs, name string, flag int, perm os.FileMode) error {
bfh, err := base.OpenFile(name, flag, perm)
if err != nil {
return err
}
defer bfh.Close()

return copyFile(base, layer, name, bfh)
}

0 comments on commit cd35605

Please sign in to comment.