Log the file type of the file before skipping it

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
pull/31250/head
Evans Mungai 3 weeks ago
parent 20054e6b56
commit bb1aeaf3ea
No known key found for this signature in database
GPG Key ID: BBEB812143DD14E1

@ -178,7 +178,8 @@ func CopyFile(src, dst string) (err error) {
if fi, err := os.Lstat(src); err != nil {
return fmt.Errorf("stat failed: %w", err)
} else if !fi.Mode().IsRegular() {
slog.Debug("skipping non-regular file", "path", src, "mode", fi.Mode())
fileType := fileTypeString(fi.Mode())
slog.Debug("skipping non-regular file", "path", src, "type", fileType, "mode", fi.Mode())
return nil
}
}
@ -254,6 +255,31 @@ func IsSymlink(path string) (bool, error) {
return l.Mode()&os.ModeSymlink == os.ModeSymlink, nil
}
// fileTypeString returns a human-readable description of the file type based on the mode.
func fileTypeString(mode os.FileMode) string {
switch {
case mode&os.ModeDir != 0:
return "directory"
case mode&os.ModeSymlink != 0:
return "symlink"
case mode&os.ModeNamedPipe != 0:
return "named pipe (FIFO)"
case mode&os.ModeSocket != 0:
return "socket"
case mode&os.ModeDevice != 0:
if mode&os.ModeCharDevice != 0 {
return "character device"
}
return "block device"
case mode&os.ModeIrregular != 0:
return "irregular file"
case mode.IsRegular():
return "regular file"
default:
return "unknown file type"
}
}
// fixLongPath returns the extended-length (\\?\-prefixed) form of
// path when needed, in order to avoid the default 260 character file
// path limit imposed by Windows. If path is not easily converted to

Loading…
Cancel
Save