...

Source file src/github.com/containerd/continuity/driver/lchmod_linux.go

Documentation: github.com/containerd/continuity/driver

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package driver
    18  
    19  import (
    20  	"os"
    21  
    22  	"golang.org/x/sys/unix"
    23  )
    24  
    25  // Lchmod changes the mode of a file not following symlinks.
    26  func (d *driver) Lchmod(path string, mode os.FileMode) error {
    27  	// On Linux, file mode is not supported for symlinks,
    28  	// and fchmodat() does not support AT_SYMLINK_NOFOLLOW,
    29  	// so symlinks need to be skipped entirely.
    30  	if st, err := os.Stat(path); err == nil && st.Mode()&os.ModeSymlink != 0 {
    31  		return nil
    32  	}
    33  
    34  	err := unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), 0)
    35  	if err != nil {
    36  		err = &os.PathError{Op: "lchmod", Path: path, Err: err}
    37  	}
    38  	return err
    39  }
    40  

View as plain text