Skip to content

Commit

Permalink
Merge pull request #136 from k0sproject/dont-chmod-on-touch
Browse files Browse the repository at this point in the history
Don't chmod on posixfsys touch
  • Loading branch information
kke authored Nov 9, 2023
2 parents d2bf7d3 + eb120a7 commit 16a1bf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions pkg/rigfs/posixfsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,20 @@ func (fsys *PosixFsys) Open(name string) (fs.File, error) {
return &file, nil
}

// OpenFile is the generalized open call; most users will use Open instead.
// OpenFile is the generalized open call; most users will use Open instead.. The perms are ignored if the file exists.
func (fsys *PosixFsys) OpenFile(name string, mode FileMode, perm FileMode) (File, error) {
var pos int64
info, err := fsys.Stat(name)
if err != nil {
// file exists
switch {
case mode&ModeRead == ModeRead:
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist}
case mode&ModeCreate == ModeCreate:
if _, err := fsys.helper("touch", name, fmt.Sprintf("%#o", perm)); err != nil {
if _, err := fsys.helper("touch", name); err != nil {
return nil, err
}
if _, err := fsys.helper("chmod", name, fmt.Sprintf("%#o", perm)); err != nil {
return nil, err
}
}
Expand All @@ -390,8 +394,10 @@ func (fsys *PosixFsys) OpenFile(name string, mode FileMode, perm FileMode) (File
case mode&ModeAppend == ModeAppend:
pos = info.Size()
case mode&ModeCreate == ModeCreate:
if _, err := fsys.helper("truncate", name, "0"); err != nil {
return nil, err
if info.Size() > 0 {
if _, err := fsys.helper("truncate", name, "0"); err != nil {
return nil, err
}
}
}
return &PosixFile{fsys: fsys, path: name, isOpen: true, size: info.Size(), pos: pos, mode: mode}, nil
Expand Down
6 changes: 4 additions & 2 deletions pkg/rigfs/righelper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ main() {
echo -n "]}"
;;
"touch")
local perm="$3"
touch "$path" && echo -n "{}"
chmod "$perm" "$path"
;;
"chmod")
local perm="$3"
chmod "$perm" "$path" && echo -n "{}"
;;
"truncate")
local pos="$3"
Expand Down

0 comments on commit 16a1bf8

Please sign in to comment.