...

Source file src/github.com/containerd/continuity/fs/diff_unix.go

Documentation: github.com/containerd/continuity/fs

     1  //go:build !windows
     2  // +build !windows
     3  
     4  /*
     5     Copyright The containerd Authors.
     6  
     7     Licensed under the Apache License, Version 2.0 (the "License");
     8     you may not use this file except in compliance with the License.
     9     You may obtain a copy of the License at
    10  
    11         http://www.apache.org/licenses/LICENSE-2.0
    12  
    13     Unless required by applicable law or agreed to in writing, software
    14     distributed under the License is distributed on an "AS IS" BASIS,
    15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16     See the License for the specific language governing permissions and
    17     limitations under the License.
    18  */
    19  
    20  package fs
    21  
    22  import (
    23  	"bytes"
    24  	"fmt"
    25  	"os"
    26  	"syscall"
    27  
    28  	"github.com/containerd/continuity/sysx"
    29  )
    30  
    31  // detectDirDiff returns diff dir options if a directory could
    32  // be found in the mount info for upper which is the direct
    33  // diff with the provided lower directory
    34  func detectDirDiff(upper, lower string) *diffDirOptions {
    35  	// TODO: get mount options for upper
    36  	// TODO: detect AUFS
    37  	// TODO: detect overlay
    38  	return nil
    39  }
    40  
    41  // compareSysStat returns whether the stats are equivalent,
    42  // whether the files are considered the same file, and
    43  // an error
    44  func compareSysStat(s1, s2 interface{}) (bool, error) {
    45  	ls1, ok := s1.(*syscall.Stat_t)
    46  	if !ok {
    47  		return false, nil
    48  	}
    49  	ls2, ok := s2.(*syscall.Stat_t)
    50  	if !ok {
    51  		return false, nil
    52  	}
    53  
    54  	return ls1.Mode == ls2.Mode && ls1.Uid == ls2.Uid && ls1.Gid == ls2.Gid && ls1.Rdev == ls2.Rdev, nil
    55  }
    56  
    57  func compareCapabilities(p1, p2 string) (bool, error) {
    58  	c1, err := sysx.LGetxattr(p1, "security.capability")
    59  	if err != nil && err != sysx.ENODATA {
    60  		return false, fmt.Errorf("failed to get xattr for %s: %w", p1, err)
    61  	}
    62  	c2, err := sysx.LGetxattr(p2, "security.capability")
    63  	if err != nil && err != sysx.ENODATA {
    64  		return false, fmt.Errorf("failed to get xattr for %s: %w", p2, err)
    65  	}
    66  	return bytes.Equal(c1, c2), nil
    67  }
    68  
    69  func isLinked(f os.FileInfo) bool {
    70  	s, ok := f.Sys().(*syscall.Stat_t)
    71  	if !ok {
    72  		return false
    73  	}
    74  	return !f.IsDir() && s.Nlink > 1
    75  }
    76  

View as plain text