Skip to content

Commit 274c424

Browse files
committed
Support setting DFS group/owner/perms
1 parent 78e5b45 commit 274c424

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

common/unixStatAdapter.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ const ( // Values cloned from x/sys/unix to avoid dependency
324324
S_IFIFO = 0x1000
325325
S_IFLNK = 0xa000
326326

327-
S_IRUSR = 0x400
328-
S_IWUSR = 0x200
329-
S_IXUSR = 0x100
330-
S_IRGRP = 0x040
331-
S_IWGRP = 0x020
332-
S_IXGRP = 0x010
333-
S_IROTH = 0x004
334-
S_IWOTH = 0x002
335-
S_IXOTH = 0x001
327+
S_IRUSR = 0400
328+
S_IWUSR = 0200
329+
S_IXUSR = 0100
330+
S_IRGRP = 0040
331+
S_IWGRP = 0020
332+
S_IXGRP = 0010
333+
S_IROTH = 0004
334+
S_IWOTH = 0002
335+
S_IXOTH = 0001
336336

337337
S_ALLPERM = 0x777
338338
)

ste/sender-blobFS.go

+56-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/Azure/azure-storage-blob-go/azblob"
2727
"net/url"
2828
"strings"
29+
"sync"
2930
"time"
3031

3132
"github.com/Azure/azure-pipeline-go/pipeline"
@@ -237,7 +238,9 @@ func (u *blobFSSenderBase) GetSourcePOSIXProperties() (common.UnixStatAdapter, e
237238
}
238239
}
239240

240-
func (u *blobFSSenderBase) SetPOSIXProperties() error {
241+
var HNSSetAccessControlFailedOnce = &sync.Once{}
242+
243+
func (u *blobFSSenderBase) SetPOSIXProperties(hnsOnly bool) error {
241244
adapter, err := u.GetSourcePOSIXProperties()
242245
if err != nil {
243246
return fmt.Errorf("failed to get POSIX properties")
@@ -249,12 +252,57 @@ func (u *blobFSSenderBase) SetPOSIXProperties() error {
249252
common.AddStatToBlobMetadata(adapter, meta)
250253
delete(meta, common.POSIXFolderMeta) // Can't be set on HNS accounts.
251254

252-
_, err = u.GetBlobURL().SetMetadata(u.jptm.Context(), meta, azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
253-
return err
255+
var AccessControlURL interface {SetAccessControl(ctx context.Context, permissions azbfs.BlobFSAccessControl) (*azbfs.PathUpdateResponse, error)}
256+
switch u.SendableEntityType() {
257+
case common.EEntityType.File(), common.EEntityType.Symlink():
258+
AccessControlURL = u.fileURL()
259+
case common.EEntityType.Folder():
260+
AccessControlURL = u.dirURL()
261+
}
262+
263+
isRoot := false
264+
if dURL, ok := AccessControlURL.(azbfs.DirectoryURL); ok {
265+
if dURL.IsFileSystemRoot() {
266+
isRoot = true
267+
}
268+
}
269+
270+
if !hnsOnly && !isRoot { // don't try to set metadata on the container
271+
_, err = u.GetBlobURL().SetMetadata(u.jptm.Context(), meta, azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
272+
if err != nil {
273+
return err
274+
}
275+
}
276+
277+
mode := adapter.FileMode()
278+
fields := []uint32{common.S_IRUSR, common.S_IWUSR, common.S_IXUSR, common.S_IRGRP, common.S_IWGRP, common.S_IXGRP, common.S_IROTH, common.S_IWOTH, common.S_IXOTH }
279+
chars := "rwx"
280+
out := ""
281+
for _, field := range fields {
282+
if mode & field == field {
283+
out += string(chars[len(out) % 3])
284+
} else {
285+
out += "-"
286+
}
287+
}
288+
289+
_, err = AccessControlURL.SetAccessControl(u.jptm.Context(), azbfs.BlobFSAccessControl{
290+
Owner: fmt.Sprint(adapter.Owner()),
291+
Group: fmt.Sprint(adapter.Group()),
292+
Permissions: out,
293+
})
294+
if err != nil { // A user could be targeting a non-HNS account with the dfs endpoint; it's best to warn rather than fail.
295+
u.jptm.LogAtLevelForCurrentTransfer(pipeline.LogError, fmt.Sprintf("Failed to set dfs owner/group: %s", err.Error()))
296+
HNSSetAccessControlFailedOnce.Do(func() {
297+
common.GetLifecycleMgr().Info("One or more files or directories have failed to set access control; check the logs for details. (are you targeting a non-HNS account?)")
298+
})
299+
}
300+
301+
return nil
254302
}
255303

256304
func (u *blobFSSenderBase) SetFolderProperties() error {
257-
return u.SetPOSIXProperties()
305+
return u.SetPOSIXProperties(false)
258306
}
259307

260308
func (u *blobFSSenderBase) DirUrlToString() string {
@@ -295,6 +343,9 @@ func (u *blobFSSenderBase) SendSymlink(linkData string) error {
295343
nil, // dfs doesn't support tags
296344
azblob.ClientProvidedKeyOptions{}, // cpk isn't used for dfs
297345
azblob.ImmutabilityPolicyOptions{}) // dfs doesn't support immutability policy
346+
if err != nil {
347+
return err
348+
}
298349

299-
return err
350+
return u.SetPOSIXProperties(true) // set only the HNS props
300351
}

ste/sender-blobFSFromLocal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (u *blobFSUploader) Epilogue() {
9595
// Write POSIX data
9696
if jptm.IsLive() {
9797
if jptm.Info().PreservePOSIXProperties {
98-
err := u.SetPOSIXProperties()
98+
err := u.SetPOSIXProperties(false) // set all posix properties
9999
if err != nil {
100100
jptm.FailActiveUpload("Setting POSIX Properties", err)
101101
}

0 commit comments

Comments
 (0)