Skip to content

Commit 33e483e

Browse files
committed
Fix exclude_by_attribute feature on POSIX
The exclude by attribute function is broken on non-Darwin POSIX: linux and freebsd. This is because those xattrs must be prefixed by a legal namespace. The old xattr library implicitly appended the user namespace to the xattr, but the current official go pkg does not (which is just as well). Also fix the test to remove the discordant old xattr dependency and provide test cases for both darwin and non-darwin POSIX.
1 parent 7cc1b42 commit 33e483e

File tree

7 files changed

+25
-30
lines changed

7 files changed

+25
-30
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require (
1515
github.com/gilbertchen/gopass v0.0.0-20170109162249-bf9dde6d0d2c
1616
github.com/gilbertchen/highwayhash v0.0.0-20221109044721-eeab1f4799d8
1717
github.com/gilbertchen/keyring v0.0.0-20221004152639-1661cbebc508
18-
github.com/gilbertchen/xattr v0.0.0-20160926155429-68e7a6806b01
1918
github.com/hirochachacha/go-smb2 v1.1.0
2019
github.com/klauspost/compress v1.16.3
2120
github.com/klauspost/reedsolomon v1.9.9

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ github.com/gilbertchen/highwayhash v0.0.0-20221109044721-eeab1f4799d8 h1:ijgl4Y+
4747
github.com/gilbertchen/highwayhash v0.0.0-20221109044721-eeab1f4799d8/go.mod h1:0lQcVva56+L1PuUFXLOsJ6arJQaU0baIH8q+IegeBhg=
4848
github.com/gilbertchen/keyring v0.0.0-20221004152639-1661cbebc508 h1:SqTyk5KkNXp7zTdTttIZSDcTrL5uau4K/2OpKvgBZVI=
4949
github.com/gilbertchen/keyring v0.0.0-20221004152639-1661cbebc508/go.mod h1:w/pisxUZezf2XzU9Ewjphcf6q1mZtOzKPHhJiuc8cag=
50-
github.com/gilbertchen/xattr v0.0.0-20160926155429-68e7a6806b01 h1:LqwS9qL6SrDkp0g0iwUkETrDdtB9gTKaIbSn9imUq5o=
51-
github.com/gilbertchen/xattr v0.0.0-20160926155429-68e7a6806b01/go.mod h1:TMlibuxKfkdtHyltooAw7+DHqRpaXs9nxaffk00Sh1Q=
5250
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
5351
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
5452
github.com/goamz/goamz v0.0.0-20180131231218-8b901b531db8 h1:G1U0vew/vA/1/hBmf1XNeyIzJJbPFVv+kb+HPl6rj6c=

src/duplicacy_entry_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package duplicacy
66

77
import (
8+
"bytes"
9+
"encoding/json"
810
"io/ioutil"
911
"math/rand"
1012
"os"
@@ -13,11 +15,10 @@ import (
1315
"sort"
1416
"strings"
1517
"testing"
16-
"bytes"
17-
"encoding/json"
1818

19-
"github.com/gilbertchen/xattr"
20-
"github.com/vmihailenco/msgpack"
19+
"github.com/pkg/xattr"
20+
21+
"github.com/vmihailenco/msgpack"
2122
)
2223

2324
func TestEntrySort(t *testing.T) {
@@ -175,7 +176,7 @@ func TestEntryOrder(t *testing.T) {
175176
directories = append(directories, CreateEntry("", 0, 0, 0))
176177

177178
entries := make([]*Entry, 0, 4)
178-
entryChannel := make(chan *Entry, 1024)
179+
entryChannel := make(chan *Entry, 1024)
179180
entries = append(entries, CreateEntry("", 0, 0, 0))
180181

181182
for len(directories) > 0 {
@@ -233,8 +234,16 @@ func TestEntryOrder(t *testing.T) {
233234
// TestEntryExcludeByAttribute tests the excludeByAttribute parameter to the ListEntries function
234235
func TestEntryExcludeByAttribute(t *testing.T) {
235236

236-
if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") {
237-
t.Skip("skipping test not darwin or linux")
237+
var excludeAttrName string
238+
var excludeAttrValue []byte
239+
240+
if runtime.GOOS == "darwin" {
241+
excludeAttrName = "com.apple.metadata:com_apple_backup_excludeItem"
242+
excludeAttrValue = []byte("com.apple.backupd")
243+
} else if runtime.GOOS == "linux" || runtime.GOOS == "freebsd" || runtime.GOOS == "netbsd" || runtime.GOOS == "solaris" {
244+
excludeAttrName = "user.duplicacy_exclude"
245+
} else {
246+
t.Skip("skipping test, not darwin, linux, freebsd, netbsd, or solaris")
238247
}
239248

240249
testDir := filepath.Join(os.TempDir(), "duplicacy_test")
@@ -273,7 +282,7 @@ func TestEntryExcludeByAttribute(t *testing.T) {
273282
for _, file := range DATA {
274283
fullPath := filepath.Join(testDir, file)
275284
if strings.Contains(file, "exclude") {
276-
xattr.Setxattr(fullPath, "com.apple.metadata:com_apple_backup_excludeItem", []byte("com.apple.backupd"))
285+
xattr.Set(fullPath, excludeAttrName, excludeAttrValue)
277286
}
278287
}
279288

@@ -372,4 +381,4 @@ func TestEntryEncoding(t *testing.T) {
372381
t.Error("Decoded entry is different than the original one")
373382
}
374383

375-
}
384+
}

src/duplicacy_utils_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
)
1010

11-
func excludedByAttribute(attirbutes map[string][]byte) bool {
12-
value, ok := attirbutes["com.apple.metadata:com_apple_backup_excludeItem"]
11+
func excludedByAttribute(attributes map[string][]byte) bool {
12+
value, ok := attributes["com.apple.metadata:com_apple_backup_excludeItem"]
1313
return ok && strings.Contains(string(value), "com.apple.backupd")
1414
}

src/duplicacy_utils_freebsd.go

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// Free for personal use and commercial trial
33
// Commercial use requires per-user licenses available from https://duplicacy.com
44

5+
// +build freebsd netbsd linux solaris
6+
57
package duplicacy
68

79
import (
810
)
911

10-
func excludedByAttribute(attirbutes map[string][]byte) bool {
11-
_, ok := attirbutes["duplicacy_exclude"]
12+
func excludedByAttribute(attributes map[string][]byte) bool {
13+
_, ok := attributes["user.duplicacy_exclude"]
1214
return ok
1315
}

src/duplicacy_utils_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@ func SplitDir(fullPath string) (dir string, file string) {
132132
return fullPath[:i+1], fullPath[i+1:]
133133
}
134134

135-
func excludedByAttribute(attirbutes map[string][]byte) bool {
135+
func excludedByAttribute(attributes map[string][]byte) bool {
136136
return false
137137
}

0 commit comments

Comments
 (0)