diff --git a/common/hash_data_other.go b/common/hash_data_other.go index 64f6a01dc..66eee166e 100644 --- a/common/hash_data_other.go +++ b/common/hash_data_other.go @@ -1,5 +1,4 @@ -//go:build !windows -// +build !windows +//go:build !windows && !linux && !darwin && !freebsd && !netbsd && !solaris package common diff --git a/common/hash_data_unix.go b/common/hash_data_unix.go new file mode 100644 index 000000000..11312695a --- /dev/null +++ b/common/hash_data_unix.go @@ -0,0 +1,35 @@ +//go:build linux || darwin || freebsd || netbsd || solaris + +// additional *NIX based OSes included since it uses a generic xattr implementation. + +package common + +import ( + "encoding/json" + "github.com/pkg/xattr" +) + +var AzCopySyncMetaXAttr = "azcopy.syncmeta" + +func TryGetHashData(fullpath string) (SyncHashData, error) { + // LGet because we want to target the file we actually specify, not what's on the other end. + buf, err := xattr.LGet(fullpath, AzCopySyncMetaXAttr) + if err != nil { + return SyncHashData{}, err + } + + var out SyncHashData + err = json.Unmarshal(buf, &out) + + return out, err +} + +func PutHashData(fullpath string, data SyncHashData) error { + buf, err := json.Marshal(data) + if err != nil { + return err + } + + // LSet because we want to target the file we actually specify, not what's on the other end. + return xattr.LSet(fullpath, AzCopySyncMetaXAttr, buf) +} diff --git a/go.mod b/go.mod index 4d9e974bf..1836f293c 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/mattn/go-ieproxy v0.0.3 github.com/minio/minio-go v6.0.14+incompatible github.com/pkg/errors v0.9.1 - github.com/pkg/xattr v0.4.6 + github.com/pkg/xattr v0.4.9 github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/spf13/cobra v1.4.0 github.com/wastore/keychain v0.0.0-20180920053336-f2c902a3d807 @@ -22,7 +22,7 @@ require ( golang.org/x/crypto v0.0.0-20220314234724-5d542ad81a58 golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 + golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f google.golang.org/api v0.72.0 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c ) diff --git a/go.sum b/go.sum index 2183e517e..bd4acf517 100644 --- a/go.sum +++ b/go.sum @@ -240,6 +240,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/xattr v0.4.6 h1:0vqthLIMxQKA9VscyMcxjvAUGvyfzlk009vwLE8OZJg= github.com/pkg/xattr v0.4.6/go.mod h1:sBD3RAqlr8Q+RC3FutZcikpT8nyDrIEEBw2J744gVWs= +github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE= +github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -460,6 +462,8 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f h1:8w7RhxzTVgUzw/AH/9mUV5q0vMgy40SQRursCcfmkCw= +golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=