mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 19:54:54 -06:00
Compare commits
4 Commits
wip-hardli
...
b2749b6e20
| Author | SHA1 | Date | |
|---|---|---|---|
| b2749b6e20 | |||
| f06779659e | |||
| 16885eaa61 | |||
| bf2565b5c3 |
@@ -304,24 +304,7 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
|
|||||||
remoteEntry = nil
|
remoteEntry = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if localEntry.IsHardlinkedFrom() {
|
if compareResult == 0 {
|
||||||
// FIXME: Sanity check?
|
|
||||||
// FIXME: perhaps we can make size = 0 an initial invariant of the link?
|
|
||||||
//
|
|
||||||
// Note that if the initial size was 0 then this original logic doesn't change!
|
|
||||||
localEntry.Size = 0
|
|
||||||
// targetEntry, ok := localEntryList.HardLinkTable[localEntry.Link]
|
|
||||||
// if !ok {
|
|
||||||
// LOG_ERROR("BACKUP_CREATE", "Hard link %s not found in entry cache for path %s", localEntry.Link, localEntry.Path)
|
|
||||||
// }
|
|
||||||
// localEntry.Size = targetEntry.Size
|
|
||||||
// localEntry.Hash = targetEntry.Hash
|
|
||||||
// localEntry.StartChunk = targetEntry.StartChunk
|
|
||||||
// localEntry.StartOffset = targetEntry.StartOffset
|
|
||||||
// localEntry.EndChunk = targetEntry.EndChunk
|
|
||||||
// localEntry.EndOffset = targetEntry.EndOffset
|
|
||||||
// LOG_DEBUG("BACKUP_CREATE", "Hard link %s to %s in initial listing", localEntry.Link, targetEntry.Path)
|
|
||||||
} else if compareResult == 0 {
|
|
||||||
// No need to check if it is in hash mode -- in that case remote listing is nil
|
// No need to check if it is in hash mode -- in that case remote listing is nil
|
||||||
if localEntry.IsSameAs(remoteEntry) && localEntry.IsFile() {
|
if localEntry.IsSameAs(remoteEntry) && localEntry.IsFile() {
|
||||||
if localEntry.Size > 0 {
|
if localEntry.Size > 0 {
|
||||||
@@ -639,11 +622,6 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
type hardLinkEntry struct {
|
|
||||||
entry *Entry
|
|
||||||
willDownload bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore downloads the specified snapshot, compares it with what's on the repository, and then downloads
|
// Restore downloads the specified snapshot, compares it with what's on the repository, and then downloads
|
||||||
// files that are different. 'base' is a directory that contains files at a different revision which can
|
// files that are different. 'base' is a directory that contains files at a different revision which can
|
||||||
// serve as a local cache to avoid download chunks available locally. It is perfectly ok for 'base' to be
|
// serve as a local cache to avoid download chunks available locally. It is perfectly ok for 'base' to be
|
||||||
@@ -725,14 +703,17 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
var localEntry *Entry
|
var localEntry *Entry
|
||||||
localListingOK := true
|
localListingOK := true
|
||||||
|
|
||||||
hardLinkTable := make(map[string]hardLinkEntry)
|
type hardLinkEntry struct {
|
||||||
//hardLinks := make([]*Entry, 0)
|
entry *Entry
|
||||||
|
willDownload bool
|
||||||
|
}
|
||||||
|
var hardLinkTable []hardLinkEntry
|
||||||
|
var hardLinks []*Entry
|
||||||
|
|
||||||
for remoteEntry := range remoteListingChannel {
|
for remoteEntry := range remoteListingChannel {
|
||||||
|
|
||||||
if remoteEntry.IsFile() && remoteEntry.Link == "/" {
|
if remoteEntry.IsHardlinkRoot() {
|
||||||
LOG_INFO("RESTORE_LINK", "Noting hardlinked source file %s", remoteEntry.Path)
|
hardLinkTable = append(hardLinkTable, hardLinkEntry{remoteEntry, false})
|
||||||
hardLinkTable[remoteEntry.Path] = hardLinkEntry{remoteEntry, false}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(patterns) > 0 && !MatchPath(remoteEntry.Path, patterns) {
|
if len(patterns) > 0 && !MatchPath(remoteEntry.Path, patterns) {
|
||||||
@@ -743,8 +724,6 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
var compareResult int
|
var compareResult int
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// TODO: We likely need to check if a local listing file exists in the hardLinkTable for the case where one is restoring a hardlink
|
|
||||||
// to an existing disk file. Right now, we'll just end up downloading the file new.
|
|
||||||
if localEntry == nil && localListingOK {
|
if localEntry == nil && localListingOK {
|
||||||
localEntry, localListingOK = <- localListingChannel
|
localEntry, localListingOK = <- localListingChannel
|
||||||
}
|
}
|
||||||
@@ -762,36 +741,19 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if compareResult == 0 {
|
if compareResult == 0 {
|
||||||
// if quickMode && localEntry.IsFile() {
|
if quickMode && localEntry.IsFile() && localEntry.IsSameAs(remoteEntry) {
|
||||||
if quickMode && localEntry.IsFile() && localEntry.IsSameAs(remoteEntry) {
|
LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", localEntry.Path)
|
||||||
LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", localEntry.Path)
|
skippedFileSize += localEntry.Size
|
||||||
skippedFileSize += localEntry.Size
|
skippedFileCount++
|
||||||
skippedFileCount++
|
localEntry = nil
|
||||||
localEntry = nil
|
continue
|
||||||
continue
|
|
||||||
// checkEntry := remoteEntry
|
|
||||||
// if len(remoteEntry.Link) > 0 && remoteEntry.Link != "/" {
|
|
||||||
// if e, ok := hardLinkTable[remoteEntry.Link]; !ok {
|
|
||||||
// LOG_ERROR("RESTORE_LINK", "Source file %s for hardlink %s missing", remoteEntry.Link, remoteEntry.Path)
|
|
||||||
// } else {
|
|
||||||
// checkEntry = e.entry
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if localEntry.IsSameAs(checkEntry) {
|
|
||||||
// LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", localEntry.Path)
|
|
||||||
// skippedFileSize += localEntry.Size
|
|
||||||
// skippedFileCount++
|
|
||||||
// localEntry = nil
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
localEntry = nil
|
localEntry = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath := joinPath(top, remoteEntry.Path)
|
fullPath := joinPath(top, remoteEntry.Path)
|
||||||
if remoteEntry.IsLink() {
|
if remoteEntry.IsLink() {
|
||||||
stat, err := os.Lstat(fullPath)
|
if stat, _ := os.Lstat(fullPath); stat != nil {
|
||||||
if stat != nil {
|
|
||||||
if stat.Mode()&os.ModeSymlink != 0 {
|
if stat.Mode()&os.ModeSymlink != 0 {
|
||||||
isRegular, link, err := Readlink(fullPath)
|
isRegular, link, err := Readlink(fullPath)
|
||||||
if err == nil && link == remoteEntry.Link && !isRegular {
|
if err == nil && link == remoteEntry.Link && !isRegular {
|
||||||
@@ -800,11 +762,16 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !overwrite {
|
||||||
|
LOG_WERROR(allowFailures, "DOWNLOAD_OVERWRITE",
|
||||||
|
"File %s already exists. Please specify the -overwrite option to overwrite", remoteEntry.Path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
os.Remove(fullPath)
|
os.Remove(fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Symlink(remoteEntry.Link, fullPath)
|
if err := os.Symlink(remoteEntry.Link, fullPath); err != nil {
|
||||||
if err != nil {
|
|
||||||
LOG_ERROR("RESTORE_SYMLINK", "Can't create symlink %s: %v", remoteEntry.Path, err)
|
LOG_ERROR("RESTORE_SYMLINK", "Can't create symlink %s: %v", remoteEntry.Path, err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -828,23 +795,24 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
remoteEntry.RestoreEarlyDirFlags(fullPath)
|
||||||
directoryEntries = append(directoryEntries, remoteEntry)
|
directoryEntries = append(directoryEntries, remoteEntry)
|
||||||
} else {
|
} else {
|
||||||
// if remoteEntry.Link == "/" {
|
if remoteEntry.IsHardlinkRoot() {
|
||||||
// hardLinkTable[remoteEntry.Path] = hardLinkEntry{remoteEntry, true}
|
hardLinkTable[len(hardLinkTable)-1] = hardLinkEntry{remoteEntry, true}
|
||||||
// } else if len(remoteEntry.Link) > 0 {
|
} else if remoteEntry.IsHardlinkedFrom() {
|
||||||
// if e, ok := hardLinkTable[remoteEntry.Link]; !ok {
|
i, err := strconv.ParseUint(remoteEntry.Link, 16, 64)
|
||||||
// LOG_ERROR("RESTORE_LINK", "Source file %s for hardlink %s missing", remoteEntry.Link, remoteEntry.Path)
|
if err != nil {
|
||||||
// } else if !e.willDownload {
|
LOG_ERROR("RESTORE_HARDLINK", "Decode error in hardlink entry, expected hex int, got %s", remoteEntry.Link)
|
||||||
// origSourcePath := e.entry.Path
|
return 0
|
||||||
// e.entry.Path = remoteEntry.Path
|
}
|
||||||
// remoteEntry = e.entry
|
if !hardLinkTable[i].willDownload {
|
||||||
// hardLinkTable[origSourcePath] = hardLinkEntry{remoteEntry, true}
|
hardLinkTable[i] = hardLinkEntry{remoteEntry, true}
|
||||||
// } else {
|
} else {
|
||||||
// hardLinks = append(hardLinks, remoteEntry)
|
hardLinks = append(hardLinks, remoteEntry)
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// We can't download files here since fileEntries needs to be sorted
|
// We can't download files here since fileEntries needs to be sorted
|
||||||
fileEntries = append(fileEntries, remoteEntry)
|
fileEntries = append(fileEntries, remoteEntry)
|
||||||
totalFileSize += remoteEntry.Size
|
totalFileSize += remoteEntry.Size
|
||||||
@@ -900,10 +868,6 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
stat, _ := os.Stat(fullPath)
|
stat, _ := os.Stat(fullPath)
|
||||||
if stat != nil {
|
if stat != nil {
|
||||||
if quickMode {
|
if quickMode {
|
||||||
// cmpFile := file
|
|
||||||
// if file.IsFile() && len(file.Link) > 0 && file.Link != "/" {
|
|
||||||
// cmpFile = hardLinkTable[file.Link].entry
|
|
||||||
// }
|
|
||||||
if file.IsSameAsFileInfo(stat) {
|
if file.IsSameAsFileInfo(stat) {
|
||||||
LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", file.Path)
|
LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", file.Path)
|
||||||
skippedFileSize += file.Size
|
skippedFileSize += file.Size
|
||||||
@@ -941,6 +905,7 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
downloadedFileSize += file.Size
|
downloadedFileSize += file.Size
|
||||||
downloadedFiles = append(downloadedFiles, file)
|
downloadedFiles = append(downloadedFiles, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -967,14 +932,16 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
file.RestoreMetadata(fullPath, nil, setOwner)
|
file.RestoreMetadata(fullPath, nil, setOwner)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for _, linkEntry := range hardLinks {
|
for _, linkEntry := range hardLinks {
|
||||||
// sourcePath := joinPath(top, hardLinkTable[linkEntry.Link].entry.Path)
|
i, _ := strconv.ParseUint(linkEntry.Link, 16, 64)
|
||||||
// fullPath := joinPath(top, linkEntry.Path)
|
sourcePath := joinPath(top, hardLinkTable[i].entry.Path)
|
||||||
// LOG_INFO("DOWNLOAD_LINK", "Hard linking %s -> %s", fullPath, sourcePath)
|
fullPath := joinPath(top, linkEntry.Path)
|
||||||
// if err := os.Link(sourcePath, fullPath); err != nil {
|
LOG_INFO("RESTORE_HARDLINK", "Hard linking %s to %s", fullPath, sourcePath)
|
||||||
// LOG_ERROR("DOWNLOAD_LINK", "Failed to create hard link %s -> %s", fullPath, sourcePath)
|
if err := os.Link(sourcePath, fullPath); err != nil {
|
||||||
// }
|
LOG_ERROR("RESTORE_HARDLINK", "Failed to create hard link %s to %s", fullPath, sourcePath)
|
||||||
// }
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if deleteMode && len(patterns) == 0 {
|
if deleteMode && len(patterns) == 0 {
|
||||||
// Reverse the order to make sure directories are empty before being deleted
|
// Reverse the order to make sure directories are empty before being deleted
|
||||||
@@ -1127,11 +1094,13 @@ func (manager *BackupManager) UploadSnapshot(chunkOperator *ChunkOperator, top s
|
|||||||
|
|
||||||
lastEndChunk := 0
|
lastEndChunk := 0
|
||||||
|
|
||||||
uploadEntryInfoFunc := func(entry *Entry) error {
|
type hardLinkEntry struct {
|
||||||
if entry.IsHardlinkRoot() {
|
entry *Entry
|
||||||
entryList.HardLinkTable[entry.Path] = entry
|
startChunk int
|
||||||
}
|
}
|
||||||
|
var hardLinkTable []hardLinkEntry
|
||||||
|
|
||||||
|
uploadEntryInfoFunc := func(entry *Entry) error {
|
||||||
if entry.IsFile() && entry.Size > 0 {
|
if entry.IsFile() && entry.Size > 0 {
|
||||||
delta := entry.StartChunk - len(chunkHashes) + 1
|
delta := entry.StartChunk - len(chunkHashes) + 1
|
||||||
if entry.StartChunk != lastChunk {
|
if entry.StartChunk != lastChunk {
|
||||||
@@ -1149,18 +1118,38 @@ func (manager *BackupManager) UploadSnapshot(chunkOperator *ChunkOperator, top s
|
|||||||
entry.StartChunk -= delta
|
entry.StartChunk -= delta
|
||||||
entry.EndChunk -= delta
|
entry.EndChunk -= delta
|
||||||
|
|
||||||
|
if entry.IsHardlinkRoot() {
|
||||||
|
LOG_DEBUG("SNAPSHOT_UPLOAD", "Hard link root %s %v %v", entry.Path, entry.StartChunk, entry.EndChunk)
|
||||||
|
hardLinkTable = append(hardLinkTable, hardLinkEntry{entry, entry.StartChunk})
|
||||||
|
}
|
||||||
|
|
||||||
delta = entry.EndChunk - entry.StartChunk
|
delta = entry.EndChunk - entry.StartChunk
|
||||||
entry.StartChunk -= lastEndChunk
|
entry.StartChunk -= lastEndChunk
|
||||||
lastEndChunk = entry.EndChunk
|
lastEndChunk = entry.EndChunk
|
||||||
entry.EndChunk = delta
|
entry.EndChunk = delta
|
||||||
} else if entry.IsHardlinkedFrom() {
|
} else if entry.IsHardlinkedFrom() {
|
||||||
targetEntry, ok := entryList.HardLinkTable[entry.Link]
|
i, err := strconv.ParseUint(entry.Link, 16, 64)
|
||||||
if !ok {
|
if err != nil {
|
||||||
LOG_ERROR("SNAPSHOT_UPLOAD", "Unable to find hardlink target for %s to %s", entry.Path, entry.Link)
|
LOG_ERROR("SNAPSHOT_UPLOAD", "Decode error in hardlink entry, expected hex int, got %s", entry.Link)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
// FIXME: We will use a copy, so it is probably sufficient to skip rereading xattrs and such in the initial code
|
|
||||||
entry = entry.LinkTo(targetEntry)
|
targetEntry := hardLinkTable[i].entry
|
||||||
LOG_DEBUG("SNAPSHOT_UPLOAD", "Uploading cloned hardlink entry for %s to %s", entry.Path, entry.Link)
|
var startChunk, endChunk int
|
||||||
|
|
||||||
|
if targetEntry.Size > 0 {
|
||||||
|
startChunk = hardLinkTable[i].startChunk - lastEndChunk
|
||||||
|
endChunk = targetEntry.EndChunk
|
||||||
|
}
|
||||||
|
entry = entry.HardLinkTo(targetEntry, startChunk, endChunk)
|
||||||
|
|
||||||
|
if targetEntry.Size > 0 {
|
||||||
|
lastEndChunk = hardLinkTable[i].startChunk + endChunk
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("SNAPSHOT_UPLOAD", "Uploading cloned hardlink for %s to %s (%v %v)", entry.Path, targetEntry.Path, startChunk, endChunk)
|
||||||
|
} else if entry.IsHardlinkRoot() {
|
||||||
|
hardLinkTable = append(hardLinkTable, hardLinkEntry{entry, 0})
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
@@ -1280,6 +1269,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
LOG_ERROR("DOWNLOAD_CREATE", "Failed to create the file %s for in-place writing: %v", fullPath, err)
|
LOG_ERROR("DOWNLOAD_CREATE", "Failed to create the file %s for in-place writing: %v", fullPath, err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
entry.RestoreEarlyFileFlags(existingFile)
|
||||||
|
|
||||||
n := int64(1)
|
n := int64(1)
|
||||||
// There is a go bug on Windows (https://github.com/golang/go/issues/21681) that causes Seek to fail
|
// There is a go bug on Windows (https://github.com/golang/go/issues/21681) that causes Seek to fail
|
||||||
@@ -1463,6 +1453,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
entry.RestoreEarlyFileFlags(existingFile)
|
||||||
|
|
||||||
existingFile.Seek(0, 0)
|
existingFile.Seek(0, 0)
|
||||||
|
|
||||||
@@ -1545,6 +1536,7 @@ func (manager *BackupManager) RestoreFile(chunkDownloader *ChunkDownloader, chun
|
|||||||
LOG_ERROR("DOWNLOAD_OPEN", "Failed to open file for writing: %v", err)
|
LOG_ERROR("DOWNLOAD_OPEN", "Failed to open file for writing: %v", err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
entry.RestoreEarlyFileFlags(newFile)
|
||||||
|
|
||||||
hasher := manager.config.NewFileHasher()
|
hasher := manager.config.NewFileHasher()
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func (entry *Entry) Copy() *Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) LinkTo(target *Entry) *Entry {
|
func (entry *Entry) HardLinkTo(target *Entry, startChunk int, endChunk int) *Entry {
|
||||||
return &Entry{
|
return &Entry{
|
||||||
Path: entry.Path,
|
Path: entry.Path,
|
||||||
Size: target.Size,
|
Size: target.Size,
|
||||||
@@ -131,9 +131,9 @@ func (entry *Entry) LinkTo(target *Entry) *Entry {
|
|||||||
UID: target.UID,
|
UID: target.UID,
|
||||||
GID: target.GID,
|
GID: target.GID,
|
||||||
|
|
||||||
StartChunk: target.StartChunk,
|
StartChunk: startChunk,
|
||||||
StartOffset: target.StartOffset,
|
StartOffset: target.StartOffset,
|
||||||
EndChunk: target.EndChunk,
|
EndChunk: endChunk,
|
||||||
EndOffset: target.EndOffset,
|
EndOffset: target.EndOffset,
|
||||||
|
|
||||||
Attributes: target.Attributes,
|
Attributes: target.Attributes,
|
||||||
@@ -513,10 +513,6 @@ func (entry *Entry) IsComplete() bool {
|
|||||||
return entry.Size >= 0
|
return entry.Size >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) IsFileNotHardlink() bool {
|
|
||||||
return entry.IsFile() && (len(entry.Link) == 0 || entry.Link == "/")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) IsHardlinkedFrom() bool {
|
func (entry *Entry) IsHardlinkedFrom() bool {
|
||||||
return entry.IsFile() && len(entry.Link) > 0 && entry.Link != "/"
|
return entry.IsFile() && len(entry.Link) > 0 && entry.Link != "/"
|
||||||
}
|
}
|
||||||
@@ -733,12 +729,13 @@ type listEntryLinkKey struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListingState struct {
|
type ListingState struct {
|
||||||
linkTable map[listEntryLinkKey]string // map unique inode details to initially found path
|
linkIndex int
|
||||||
|
linkTable map[listEntryLinkKey]int // map unique inode details to initially found path
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListingState() *ListingState {
|
func NewListingState() *ListingState {
|
||||||
return &ListingState{
|
return &ListingState{
|
||||||
linkTable: make(map[listEntryLinkKey]string),
|
linkTable: make(map[listEntryLinkKey]int),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -820,6 +817,30 @@ func ListEntries(top string, path string, patterns []string, nobackupFile string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f.Mode()&(os.ModeNamedPipe|os.ModeSocket|os.ModeDevice) != 0 {
|
||||||
|
LOG_WARN("LIST_SKIP", "Skipped non-regular file %s", entry.Path)
|
||||||
|
skippedFiles = append(skippedFiles, entry.Path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var linkKey *listEntryLinkKey
|
||||||
|
|
||||||
|
if stat, ok := f.Sys().(*syscall.Stat_t); entry.IsFile() && ok && stat != nil && stat.Nlink > 1 {
|
||||||
|
k := listEntryLinkKey{dev: uint64(stat.Dev), ino: uint64(stat.Ino)}
|
||||||
|
if linkIndex, seen := listingState.linkTable[k]; seen {
|
||||||
|
if linkIndex == -1 {
|
||||||
|
LOG_DEBUG("LIST_EXCLUDE", "%s is excluded by attribute (hardlink)", entry.Path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
entry.Size = 0
|
||||||
|
entry.Link = strconv.FormatInt(int64(linkIndex), 16)
|
||||||
|
} else {
|
||||||
|
entry.Link = "/"
|
||||||
|
listingState.linkTable[k] = -1
|
||||||
|
linkKey = &k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entry.ReadAttributes(top)
|
entry.ReadAttributes(top)
|
||||||
|
|
||||||
if excludeByAttribute && entry.Attributes != nil && excludedByAttribute(*entry.Attributes) {
|
if excludeByAttribute && entry.Attributes != nil && excludedByAttribute(*entry.Attributes) {
|
||||||
@@ -827,24 +848,9 @@ func ListEntries(top string, path string, patterns []string, nobackupFile string
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Mode()&(os.ModeNamedPipe|os.ModeSocket|os.ModeDevice) != 0 {
|
if linkKey != nil {
|
||||||
LOG_WARN("LIST_SKIP", "Skipped non-regular file %s", entry.Path)
|
listingState.linkTable[*linkKey] = listingState.linkIndex
|
||||||
skippedFiles = append(skippedFiles, entry.Path)
|
listingState.linkIndex++
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if entry.IsFile() {
|
|
||||||
stat, ok := f.Sys().(*syscall.Stat_t)
|
|
||||||
if ok && stat != nil && stat.Nlink > 1 {
|
|
||||||
k := listEntryLinkKey{dev: uint64(stat.Dev), ino: uint64(stat.Ino)}
|
|
||||||
if path, ok := listingState.linkTable[k]; ok {
|
|
||||||
LOG_DEBUG("LIST_HARDLINK", "Detected hardlink %s to %s", entry.Path, path)
|
|
||||||
entry.Link = path
|
|
||||||
} else {
|
|
||||||
entry.Link = "/"
|
|
||||||
listingState.linkTable[k] = entry.Path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ type EntryList struct {
|
|||||||
uploadedChunkIndex int // counter for upload chunks
|
uploadedChunkIndex int // counter for upload chunks
|
||||||
uploadedChunkOffset int // the start offset for the current modified entry
|
uploadedChunkOffset int // the start offset for the current modified entry
|
||||||
|
|
||||||
HardLinkTable map[string]*Entry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new entry list
|
// Create a new entry list
|
||||||
@@ -79,7 +78,6 @@ func CreateEntryList(snapshotID string, cachePath string, maximumInMemoryEntries
|
|||||||
maximumInMemoryEntries: maximumInMemoryEntries,
|
maximumInMemoryEntries: maximumInMemoryEntries,
|
||||||
cachePath: cachePath,
|
cachePath: cachePath,
|
||||||
Token: string(token),
|
Token: string(token),
|
||||||
HardLinkTable: make(map[string]*Entry),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return entryList, nil
|
return entryList, nil
|
||||||
@@ -120,7 +118,7 @@ func (entryList *EntryList)AddEntry(entry *Entry) error {
|
|||||||
if !entry.IsComplete() {
|
if !entry.IsComplete() {
|
||||||
if entry.IsDir() || entry.IsLink() {
|
if entry.IsDir() || entry.IsLink() {
|
||||||
entry.Size = 0
|
entry.Size = 0
|
||||||
} else if !entry.IsHardlinkedFrom() {
|
} else {
|
||||||
modifiedEntry := ModifiedEntry {
|
modifiedEntry := ModifiedEntry {
|
||||||
Path: entry.Path,
|
Path: entry.Path,
|
||||||
Size: -1,
|
Size: -1,
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (snapshot *Snapshot) ListLocalFiles(top string, nobackupFile string,
|
|||||||
skippedDirectories *[]string, skippedFiles *[]string) {
|
skippedDirectories *[]string, skippedFiles *[]string) {
|
||||||
|
|
||||||
var patterns []string
|
var patterns []string
|
||||||
var listingState = NewListingState()
|
listingState := NewListingState()
|
||||||
|
|
||||||
if filtersFile == "" {
|
if filtersFile == "" {
|
||||||
filtersFile = joinPath(GetDuplicacyPreferencePath(), "filters")
|
filtersFile = joinPath(GetDuplicacyPreferencePath(), "filters")
|
||||||
|
|||||||
90
src/duplicacy_utils_bsd_common.go
Normal file
90
src/duplicacy_utils_bsd_common.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
// Copyright (c) Acrosync LLC. All rights reserved.
|
||||||
|
// Free for personal use and commercial trial
|
||||||
|
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||||
|
|
||||||
|
//go:build freebsd || netbsd || darwin
|
||||||
|
// +build freebsd netbsd darwin
|
||||||
|
|
||||||
|
package duplicacy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"bytes"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/pkg/xattr"
|
||||||
|
)
|
||||||
|
|
||||||
|
const bsdFileFlagsKey = "\x00bf"
|
||||||
|
|
||||||
|
func (entry *Entry) ReadAttributes(top string) {
|
||||||
|
fullPath := filepath.Join(top, entry.Path)
|
||||||
|
fileInfo, err := os.Lstat(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
attributes, _ := xattr.LList(fullPath)
|
||||||
|
if len(attributes) > 0 {
|
||||||
|
entry.Attributes = &map[string][]byte{}
|
||||||
|
for _, name := range attributes {
|
||||||
|
attribute, err := xattr.LGet(fullPath, name)
|
||||||
|
if err == nil {
|
||||||
|
(*entry.Attributes)[name] = attribute
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := entry.readFileFlags(fileInfo); err != nil {
|
||||||
|
LOG_INFO("ATTR_BACKUP", "Could not backup flags for file %s: %v", fullPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) SetAttributesToFile(fullPath string) {
|
||||||
|
names, _ := xattr.LList(fullPath)
|
||||||
|
for _, name := range names {
|
||||||
|
newAttribute, found := (*entry.Attributes)[name]
|
||||||
|
if found {
|
||||||
|
oldAttribute, _ := xattr.LGet(fullPath, name)
|
||||||
|
if !bytes.Equal(oldAttribute, newAttribute) {
|
||||||
|
xattr.LSet(fullPath, name, newAttribute)
|
||||||
|
}
|
||||||
|
delete(*entry.Attributes, name)
|
||||||
|
} else {
|
||||||
|
xattr.LRemove(fullPath, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, attribute := range *entry.Attributes {
|
||||||
|
if len(name) > 0 && name[0] == '\x00' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
xattr.LSet(fullPath, name, attribute)
|
||||||
|
}
|
||||||
|
if err := entry.restoreLateFileFlags(fullPath); err != nil {
|
||||||
|
LOG_DEBUG("ATTR_RESTORE", "Could not restore flags for file %s: %v", fullPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) readFileFlags(fileInfo os.FileInfo) error {
|
||||||
|
stat, ok := fileInfo.Sys().(*syscall.Stat_t)
|
||||||
|
if ok && stat.Flags != 0 {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
entry.Attributes = &map[string][]byte{}
|
||||||
|
}
|
||||||
|
v := make([]byte, 4)
|
||||||
|
binary.LittleEndian.PutUint32(v, stat.Flags)
|
||||||
|
(*entry.Attributes)[bsdFileFlagsKey] = v
|
||||||
|
LOG_DEBUG("ATTR_READ", "Read flags 0x%x for %s", stat.Flags, entry.Path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreEarlyDirFlags(path string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreEarlyFileFlags(f *os.File) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,10 +5,29 @@
|
|||||||
package duplicacy
|
package duplicacy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
"strings"
|
"strings"
|
||||||
|
"encoding/binary"
|
||||||
)
|
)
|
||||||
|
|
||||||
func excludedByAttribute(attributes map[string][]byte) bool {
|
func excludedByAttribute(attributes map[string][]byte) bool {
|
||||||
value, ok := attributes["com.apple.metadata:com_apple_backup_excludeItem"]
|
value, ok := attributes["com.apple.metadata:com_apple_backup_excludeItem"]
|
||||||
return ok && strings.Contains(string(value), "com.apple.backupd")
|
return ok && strings.Contains(string(value), "com.apple.backupd")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) restoreLateFileFlags(path string) error {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if v, have := (*entry.Attributes)[bsdFileFlagsKey]; have {
|
||||||
|
f, err := os.OpenFile(path, os.O_RDONLY|syscall.O_SYMLINK, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = syscall.Fchflags(int(f.Fd()), int(binary.LittleEndian.Uint32(v)))
|
||||||
|
f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
222
src/duplicacy_utils_linux.go
Normal file
222
src/duplicacy_utils_linux.go
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
// Copyright (c) Acrosync LLC. All rights reserved.
|
||||||
|
// Free for personal use and commercial trial
|
||||||
|
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||||
|
|
||||||
|
package duplicacy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/pkg/xattr"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
linux_FS_SECRM_FL = 0x00000001 /* Secure deletion */
|
||||||
|
linux_FS_UNRM_FL = 0x00000002 /* Undelete */
|
||||||
|
linux_FS_COMPR_FL = 0x00000004 /* Compress file */
|
||||||
|
linux_FS_SYNC_FL = 0x00000008 /* Synchronous updates */
|
||||||
|
linux_FS_IMMUTABLE_FL = 0x00000010 /* Immutable file */
|
||||||
|
linux_FS_APPEND_FL = 0x00000020 /* writes to file may only append */
|
||||||
|
linux_FS_NODUMP_FL = 0x00000040 /* do not dump file */
|
||||||
|
linux_FS_NOATIME_FL = 0x00000080 /* do not update atime */
|
||||||
|
linux_FS_NOCOMP_FL = 0x00000400 /* Don't compress */
|
||||||
|
linux_FS_JOURNAL_DATA_FL = 0x00004000 /* Reserved for ext3 */
|
||||||
|
linux_FS_NOTAIL_FL = 0x00008000 /* file tail should not be merged */
|
||||||
|
linux_FS_DIRSYNC_FL = 0x00010000 /* dirsync behaviour (directories only) */
|
||||||
|
linux_FS_TOPDIR_FL = 0x00020000 /* Top of directory hierarchies*/
|
||||||
|
linux_FS_NOCOW_FL = 0x00800000 /* Do not cow file */
|
||||||
|
linux_FS_PROJINHERIT_FL = 0x20000000 /* Create with parents projid */
|
||||||
|
|
||||||
|
linux_FS_IOC_GETFLAGS uintptr = 0x80086601
|
||||||
|
linux_FS_IOC_SETFLAGS uintptr = 0x40086602
|
||||||
|
|
||||||
|
linuxIocFlagsFileEarly = linux_FS_SECRM_FL | linux_FS_UNRM_FL | linux_FS_COMPR_FL | linux_FS_NODUMP_FL | linux_FS_NOATIME_FL | linux_FS_NOCOMP_FL | linux_FS_JOURNAL_DATA_FL | linux_FS_NOTAIL_FL | linux_FS_NOCOW_FL
|
||||||
|
linuxIocFlagsDirEarly = linux_FS_TOPDIR_FL | linux_FS_PROJINHERIT_FL
|
||||||
|
linuxIocFlagsLate = linux_FS_SYNC_FL | linux_FS_IMMUTABLE_FL | linux_FS_APPEND_FL | linux_FS_DIRSYNC_FL
|
||||||
|
|
||||||
|
linuxFileFlagsKey = "\x00lf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ioctl(f *os.File, request uintptr, attrp *uint32) error {
|
||||||
|
argp := uintptr(unsafe.Pointer(attrp))
|
||||||
|
|
||||||
|
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), request, argp); errno != 0 {
|
||||||
|
return os.NewSyscallError("ioctl", errno)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type xattrHandle struct {
|
||||||
|
f *os.File
|
||||||
|
fullPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x xattrHandle) list() ([]string, error) {
|
||||||
|
if x.f != nil {
|
||||||
|
return xattr.FList(x.f)
|
||||||
|
} else {
|
||||||
|
return xattr.LList(x.fullPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x xattrHandle) get(name string) ([]byte, error) {
|
||||||
|
if x.f != nil {
|
||||||
|
return xattr.FGet(x.f, name)
|
||||||
|
} else {
|
||||||
|
return xattr.LGet(x.fullPath, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x xattrHandle) set(name string, value []byte) error {
|
||||||
|
if x.f != nil {
|
||||||
|
return xattr.FSet(x.f, name, value)
|
||||||
|
} else {
|
||||||
|
return xattr.LSet(x.fullPath, name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x xattrHandle) remove(name string) error {
|
||||||
|
if x.f != nil {
|
||||||
|
return xattr.FRemove(x.f, name)
|
||||||
|
} else {
|
||||||
|
return xattr.LSet(x.fullPath, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) ReadAttributes(top string) {
|
||||||
|
x := xattrHandle{nil, filepath.Join(top, entry.Path)}
|
||||||
|
|
||||||
|
if !entry.IsLink() {
|
||||||
|
x.f, err := os.OpenFile(fullPath, os.O_RDONLY|syscall.O_NOFOLLOW|syscall.O_NONBLOCK, 0)
|
||||||
|
if err != nil {
|
||||||
|
// FIXME: We really should return errors for failure to read
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes, _ := x.list()
|
||||||
|
|
||||||
|
if len(attributes) > 0 {
|
||||||
|
entry.Attributes = &map[string][]byte{}
|
||||||
|
}
|
||||||
|
for _, name := range attributes {
|
||||||
|
attribute, err := x.get(f, name)
|
||||||
|
if err == nil {
|
||||||
|
(*entry.Attributes)[name] = attribute
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if entry.IsFile() || entry.IsDir() {
|
||||||
|
if err := entry.readFileFlags(x.f); err != nil {
|
||||||
|
LOG_INFO("ATTR_BACKUP", "Could not backup flags for file %s: %v", fullPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) SetAttributesToFile(fullPath string) {
|
||||||
|
x := xattrHandle{nil, fullPath}
|
||||||
|
if !entry.IsLink() {
|
||||||
|
x.f, err := os.OpenFile(fullPath, os.O_RDONLY|syscall.O_NOFOLLOW, 0)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
names, _ := x.list()
|
||||||
|
|
||||||
|
for _, name := range names {
|
||||||
|
newAttribute, found := (*entry.Attributes)[name]
|
||||||
|
if found {
|
||||||
|
oldAttribute, _ := x.get(name)
|
||||||
|
if !bytes.Equal(oldAttribute, newAttribute) {
|
||||||
|
x.set(name, newAttribute)
|
||||||
|
}
|
||||||
|
delete(*entry.Attributes, name)
|
||||||
|
} else {
|
||||||
|
x.remove(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, attribute := range *entry.Attributes {
|
||||||
|
if len(name) > 0 && name[0] == '\x00' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
x.set(name, attribute)
|
||||||
|
}
|
||||||
|
if entry.IsFile() || entry.IsDir() {
|
||||||
|
if err := entry.restoreLateFileFlags(f); err != nil {
|
||||||
|
LOG_DEBUG("ATTR_RESTORE", "Could not restore flags for file %s: %v", fullPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) readFileFlags(f *os.File) error {
|
||||||
|
var flags uint32
|
||||||
|
if err := ioctl(f, linux_FS_IOC_GETFLAGS, &flags); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if flags != 0 {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
entry.Attributes = &map[string][]byte{}
|
||||||
|
}
|
||||||
|
v := make([]byte, 4)
|
||||||
|
binary.LittleEndian.PutUint32(v, flags)
|
||||||
|
(*entry.Attributes)[linuxFileFlagsKey] = v
|
||||||
|
LOG_DEBUG("ATTR_READ", "Read flags 0x%x for %s", flags, entry.Path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreEarlyDirFlags(path string) error {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if v, have := (*entry.Attributes)[linuxFileFlagsKey]; have {
|
||||||
|
flags := binary.LittleEndian.Uint32(v) & linuxIocFlagsDirEarly
|
||||||
|
f, err := os.OpenFile(path, os.O_RDONLY|syscall.O_DIRECTORY, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
LOG_DEBUG("ATTR_RESTORE", "Restore dir flags (early) 0x%x for %s", flags, entry.Path)
|
||||||
|
err = ioctl(f, linux_FS_IOC_SETFLAGS, &flags)
|
||||||
|
f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreEarlyFileFlags(f *os.File) error {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if v, have := (*entry.Attributes)[linuxFileFlagsKey]; have {
|
||||||
|
flags := binary.LittleEndian.Uint32(v) & linuxIocFlagsFileEarly
|
||||||
|
LOG_DEBUG("ATTR_RESTORE", "Restore flags (early) 0x%x for %s", flags, entry.Path)
|
||||||
|
return ioctl(f, linux_FS_IOC_SETFLAGS, &flags)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) restoreLateFileFlags(f *os.File) error {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if v, have := (*entry.Attributes)[linuxFileFlagsKey]; have {
|
||||||
|
flags := binary.LittleEndian.Uint32(v) & (linuxIocFlagsFileEarly | linuxIocFlagsDirEarly | linuxIocFlagsLate)
|
||||||
|
LOG_DEBUG("ATTR_RESTORE", "Restore flags (late) 0x%x for %s", flags, entry.Path)
|
||||||
|
return ioctl(f, linux_FS_IOC_SETFLAGS, &flags)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func excludedByAttribute(attributes map[string][]byte) bool {
|
||||||
|
_, ok := attributes["user.duplicacy_exclude"]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
@@ -2,18 +2,15 @@
|
|||||||
// Free for personal use and commercial trial
|
// Free for personal use and commercial trial
|
||||||
// Commercial use requires per-user licenses available from https://duplicacy.com
|
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||||
|
|
||||||
|
//go:build !windows
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package duplicacy
|
package duplicacy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/xattr"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Readlink(path string) (isRegular bool, s string, err error) {
|
func Readlink(path string) (isRegular bool, s string, err error) {
|
||||||
@@ -47,45 +44,6 @@ func SetOwner(fullPath string, entry *Entry, fileInfo *os.FileInfo) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) ReadAttributes(top string) {
|
|
||||||
|
|
||||||
fullPath := filepath.Join(top, entry.Path)
|
|
||||||
attributes, _ := xattr.List(fullPath)
|
|
||||||
if len(attributes) > 0 {
|
|
||||||
entry.Attributes = &map[string][]byte{}
|
|
||||||
for _, name := range attributes {
|
|
||||||
attribute, err := xattr.Get(fullPath, name)
|
|
||||||
if err == nil {
|
|
||||||
(*entry.Attributes)[name] = attribute
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (entry *Entry) SetAttributesToFile(fullPath string) {
|
|
||||||
names, _ := xattr.List(fullPath)
|
|
||||||
|
|
||||||
for _, name := range names {
|
|
||||||
|
|
||||||
|
|
||||||
newAttribute, found := (*entry.Attributes)[name]
|
|
||||||
if found {
|
|
||||||
oldAttribute, _ := xattr.Get(fullPath, name)
|
|
||||||
if !bytes.Equal(oldAttribute, newAttribute) {
|
|
||||||
xattr.Set(fullPath, name, newAttribute)
|
|
||||||
}
|
|
||||||
delete(*entry.Attributes, name)
|
|
||||||
} else {
|
|
||||||
xattr.Remove(fullPath, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, attribute := range *entry.Attributes {
|
|
||||||
xattr.Set(fullPath, name, attribute)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func joinPath(components ...string) string {
|
func joinPath(components ...string) string {
|
||||||
return path.Join(components...)
|
return path.Join(components...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// Free for personal use and commercial trial
|
// Free for personal use and commercial trial
|
||||||
// Commercial use requires per-user licenses available from https://duplicacy.com
|
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||||
|
|
||||||
//go:build freebsd || netbsd || linux || solaris
|
//go:build freebsd || netbsd || solaris
|
||||||
// +build freebsd netbsd linux solaris
|
// +build freebsd netbsd solaris
|
||||||
|
|
||||||
package duplicacy
|
package duplicacy
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,18 @@ func SplitDir(fullPath string) (dir string, file string) {
|
|||||||
return fullPath[:i+1], fullPath[i+1:]
|
return fullPath[:i+1], fullPath[i+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func excludedByAttribute(attributes map[string][]byte) bool {
|
func (entry *Entry) ReadFileFlags(f *os.File) error {
|
||||||
return false
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreEarlyDirFlags(path string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreEarlyFileFlags(f *os.File) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) RestoreLateFileFlags(f *os.File) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/duplicacy_utils_xbsd.go
Normal file
30
src/duplicacy_utils_xbsd.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (c) Acrosync LLC. All rights reserved.
|
||||||
|
// Free for personal use and commercial trial
|
||||||
|
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||||
|
|
||||||
|
//go:build freebsd || netbsd
|
||||||
|
// +build freebsd netbsd
|
||||||
|
|
||||||
|
package duplicacy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/pkg/xattr"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (entry *Entry) restoreLateFileFlags(path string) error {
|
||||||
|
if entry.Attributes == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if v, have := (*entry.Attributes)[bsdFileFlagsKey]; have {
|
||||||
|
if _, _, errno := syscall.Syscall(syscall.SYS_LCHFLAGS, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))), uintptr(v), 0); errno != 0 {
|
||||||
|
return os.NewSyscallError("lchflags", errno)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user