From 28efe91c3f46012092fa0ab7064ad70d0ebacbc0 Mon Sep 17 00:00:00 2001 From: "John K. Luebs" Date: Wed, 4 Oct 2023 02:12:17 -0500 Subject: [PATCH] Support backup of sockets This only works on Linux. Darwin does not allow mknod of a socket. Have not tested BSD. --- src/duplicacy_entry.go | 5 +---- src/duplicacy_utils_bsd_common.go | 15 +++++++++++++++ src/duplicacy_utils_linux.go | 17 +++++++++++++++++ src/duplicacy_utils_others.go | 15 --------------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/duplicacy_entry.go b/src/duplicacy_entry.go index 45f7c8f..dd7ddd9 100644 --- a/src/duplicacy_entry.go +++ b/src/duplicacy_entry.go @@ -516,7 +516,7 @@ func (entry *Entry) IsLink() bool { } func (entry *Entry) IsSpecial() bool { - return entry.Mode&uint32(os.ModeNamedPipe|os.ModeDevice|os.ModeCharDevice) != 0 + return entry.Mode&uint32(os.ModeNamedPipe|os.ModeDevice|os.ModeCharDevice|os.ModeSocket) != 0 } func (entry *Entry) IsFileOrSpecial() bool { @@ -807,9 +807,6 @@ func ListEntries(top string, path string, patterns []string, nobackupFile string if f.Name() == DUPLICACY_DIRECTORY { continue } - if f.Mode()&os.ModeSocket != 0 { - continue - } entry := CreateEntryFromFileInfo(f, normalizedPath) if len(patterns) > 0 && !MatchPath(entry.Path, patterns) { diff --git a/src/duplicacy_utils_bsd_common.go b/src/duplicacy_utils_bsd_common.go index 73e56b3..63b187f 100644 --- a/src/duplicacy_utils_bsd_common.go +++ b/src/duplicacy_utils_bsd_common.go @@ -92,3 +92,18 @@ func (entry *Entry) RestoreEarlyDirFlags(path string) error { func (entry *Entry) RestoreEarlyFileFlags(f *os.File) error { return nil } + +func (entry *Entry) RestoreSpecial(fullPath string) error { + mode := entry.Mode & uint32(fileModeMask) + + if entry.Mode&uint32(os.ModeNamedPipe) != 0 { + mode |= syscall.S_IFIFO + } else if entry.Mode&uint32(os.ModeCharDevice) != 0 { + mode |= syscall.S_IFCHR + } else if entry.Mode&uint32(os.ModeDevice) != 0 { + mode |= syscall.S_IFBLK + } else { + return nil + } + return syscall.Mknod(fullPath, mode, int(entry.GetRdev())) +} diff --git a/src/duplicacy_utils_linux.go b/src/duplicacy_utils_linux.go index 8779a49..8beeb07 100644 --- a/src/duplicacy_utils_linux.go +++ b/src/duplicacy_utils_linux.go @@ -219,6 +219,23 @@ func (entry *Entry) restoreLateFileFlags(f *os.File) error { return nil } +func (entry *Entry) RestoreSpecial(fullPath string) error { + mode := entry.Mode & uint32(fileModeMask) + + if entry.Mode&uint32(os.ModeNamedPipe) != 0 { + mode |= syscall.S_IFIFO + } else if entry.Mode&uint32(os.ModeCharDevice) != 0 { + mode |= syscall.S_IFCHR + } else if entry.Mode&uint32(os.ModeDevice) != 0 { + mode |= syscall.S_IFBLK + } else if entry.Mode&uint32(os.ModeSocket) != 0 { + mode |= syscall.S_IFSOCK + } else { + return nil + } + return syscall.Mknod(fullPath, mode, int(entry.GetRdev())) +} + func excludedByAttribute(attributes map[string][]byte) bool { _, ok := attributes["user.duplicacy_exclude"] return ok diff --git a/src/duplicacy_utils_others.go b/src/duplicacy_utils_others.go index 6632df4..c475f57 100644 --- a/src/duplicacy_utils_others.go +++ b/src/duplicacy_utils_others.go @@ -65,21 +65,6 @@ func (entry *Entry) GetRdev() uint64 { return uint64(entry.StartChunk) | uint64(entry.StartOffset)<<32 } -func (entry *Entry) RestoreSpecial(fullPath string) error { - mode := entry.Mode & uint32(fileModeMask) - - if entry.Mode&uint32(os.ModeNamedPipe) != 0 { - mode |= syscall.S_IFIFO - } else if entry.Mode&uint32(os.ModeCharDevice) != 0 { - mode |= syscall.S_IFCHR - } else if entry.Mode&uint32(os.ModeDevice) != 0 { - mode |= syscall.S_IFBLK - } else { - return nil - } - return syscall.Mknod(fullPath, mode, int(entry.GetRdev())) -} - func (entry *Entry) IsSameSpecial(fileInfo os.FileInfo) bool { stat := fileInfo.Sys().(*syscall.Stat_t) if stat == nil {