Skip to content

Commit

Permalink
fix(marmounter): Support truncate without open file
Browse files Browse the repository at this point in the history
  • Loading branch information
rinsuki committed May 4, 2024
1 parent b743455 commit 2a1fc9e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions marmounter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,17 @@ func (fs *MayakashiFS) whiteoutIfNeeded(path string) {
}
}

func (fs *MayakashiFS) removeWhiteout(path string) {
whiteoutPath := fs.getOverlayWhiteoutPath(path)
if whiteoutPath == nil {
return
}
err := os.Remove(*whiteoutPath)
if err != nil {
fmt.Println("failed to remove whiteout", err)
}
}

func (fs *MayakashiFS) Unlink(path string) int {
defer recoverHandler()
if overlayPath := fs.getOverlayPath(path); overlayPath != nil {
Expand Down Expand Up @@ -1171,6 +1182,30 @@ func (fs *MayakashiFS) Truncate(path string, size int64, fh uint64) int {

return 0
}

// ファイルを開かずに truncate される場合がある
if overlayPath := fs.getOverlayPath(path); overlayPath != nil {
err := os.Truncate(*overlayPath, size)
if err == nil {
return 0
} else if os.IsNotExist(err) && size == 0 {
// archive にしかファイルがない場合は size == 0 だけ対応 (writeback が面倒)
if _, ok := fs.Files[NormalizeString(path)]; !ok {
return -fuse.ENOENT
}
fs.removeWhiteout(path)
fp, err := os.Create(*overlayPath)
if err != nil {
fmt.Println("failed to create", err)
return -fuse.EIO
}
fp.Close()
return 0
} else {
fmt.Println("failed to truncate", err)
return -fuse.EIO
}
}
println("tried to truncate on archive file", path, size, fh)
return -fuse.EROFS
}
Expand Down

0 comments on commit 2a1fc9e

Please sign in to comment.