Skip to content

Commit

Permalink
Devex 1440 xattr write (#42)
Browse files Browse the repository at this point in the history
Supporting writing and removing xattrs
  • Loading branch information
orodeh authored Jan 29, 2020
1 parent f964a56 commit 004d66f
Show file tree
Hide file tree
Showing 9 changed files with 589 additions and 104 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,39 @@ sudo umount MOUNT-POINT

## Extended attributes (xattrs)

DNXa data objects have properties and tags, these are exposed as POSIX extended attributes. To list all attributes for a file you can do:
DNXa data objects have properties and tags, these are exposed as POSIX extended attributes. The package we use for testing is `xattr` which is native on MacOS (OSX), and can be installed with `sudo apt-get install xattr` on Linux. Xattrs can be written and removed. The examples here use `xattr`, although other tools will work just as well.

DNAx tags and properties are prefixed. For example, if `zebra.txt` is a file then `xattr -l zebra.txt` will print out all the tags, properties, and attributes that have no POSIX equivalent. These are split into three correspnding prefixes _tag_, _prop_, and _base_ all under the `user` Linux namespace.

Here `zebra.txt` has no properties or tags.
```
$ xattr -l zebra.txt
base.state: closed
base.archivalState: live
base.id: file-xxxx
```

Add a property named `family` with value `mammal`
```
$ xattr -w prop.family mammal zebra.txt
```

Add a tag `africa`
```
$ getfattr -d -m - FILENAME
$ xattr -w tag.africa XXX zebra.txt
```

The `getattr` utility is part of the ubuntu attr apt package. It can be installed with:
Remove the `family` property:
```
$ sudo apt-get install attr
$ xattr -d prop.family zebra.txt
```

Currently, read-only access is provided for tags and attributes; they cannot be set. The `state`, `archivalState`, and `id` are also exposed as xattrs.
You cannot modify any _base.*_ attribute, these are read-only. Currently, setting and deleting xattrs can be done only for files that are closed on the platform.

## Mac OS (OSX)

For OSX you will need to install [OSXFUSE](http://osxfuse.github.com/).
For OSX you will need to install [OSXFUSE](http://osxfuse.github.com/). Note that Your Milage May Vary (YMMV) on this platform, we are focused on Linux currently.

# Common problems

Expand Down
24 changes: 24 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Release Notes

## v0.19
Improvements to extended attributes (xattrs). The testing tool we use is `xattr`, which is native on MacOS (OSX), and can be installed with `sudo apt-get install xattr` on Linux.

- Xattrs can be written and removed, with the current limitation that this works only for closed files.
- Tags and properties are namespaced. For example, if `zebra.txt` is a normal text file with no DNAx tags or properties then `xattr -l` will print out all the tags, properties, and extra attributes that have no POSIX equivalent. This is split into three namespaces: _base_, _prop_, and _tag_.

```
$ xattr -l zebra.txt
base.state: closed
base.archivalState: live
base.id: file-Fjj89YQ04J96Yg3K51FKf9f7
```

Add a property named `family` with value `mammal`
```
$ xattr -w prop.family mammal zebra.txt
```

Add a tag `africa`
```
$ xattr -w tag.africa XXX zebra.txt
```

## v0.18
- Showing archived and open files; these were previously hidden. Trying to read or write from an archived
or non-closed file will cause an EACCES error.
Expand Down
131 changes: 131 additions & 0 deletions dx_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,134 @@ func (ops *DxOps) DxClone(

return true, nil
}

type RequestSetProperties struct {
ProjId string `json:"project"`
Properties map[string](*string) `json:"properties"`
}

type ReplySetProperties struct {
Id string `json:"id"`
}

func (ops *DxOps) DxSetProperty(
ctx context.Context,
httpClient *retryablehttp.Client,
projId string,
objId string,
key string,
value *string) error {

var request RequestSetProperties
request.ProjId = projId
props := make(map[string](*string))
props[key] = value
request.Properties = props

payload, err := json.Marshal(request)
if err != nil {
return err
}

repJs, err := dxda.DxAPI(
ctx, httpClient, NumRetriesDefault, &ops.dxEnv,
fmt.Sprintf("%s/setProperties", objId),
string(payload))
if err != nil {
return err
}

var reply ReplySetProperties
if err := json.Unmarshal(repJs, &reply); err != nil {
return err
}

return nil
}

type RequestAddTags struct {
ProjId string `json:"project"`
Tags []string `json:"tags"`
}

type ReplyAddTags struct {
Id string `json:"id"`
}

func (ops *DxOps) DxAddTag(
ctx context.Context,
httpClient *retryablehttp.Client,
projId string,
objId string,
key string) error {

var request RequestAddTags
request.ProjId = projId
tags := make([]string, 1)
tags[0] = key
request.Tags = tags

payload, err := json.Marshal(request)
if err != nil {
return err
}

repJs, err := dxda.DxAPI(
ctx, httpClient, NumRetriesDefault, &ops.dxEnv,
fmt.Sprintf("%s/addTags", objId),
string(payload))
if err != nil {
return err
}

var reply ReplyAddTags
if err := json.Unmarshal(repJs, &reply); err != nil {
return err
}

return nil
}


type RequestRemoveTags struct {
ProjId string `json:"project"`
Tags []string `json:"tags"`
}

type ReplyRemoveTags struct {
Id string `json:"id"`
}

func (ops *DxOps) DxRemoveTag(
ctx context.Context,
httpClient *retryablehttp.Client,
projId string,
objId string,
key string) error {

var request RequestRemoveTags
request.ProjId = projId
tags := make([]string, 1)
tags[0] = key
request.Tags = tags

payload, err := json.Marshal(request)
if err != nil {
return err
}

repJs, err := dxda.DxAPI(
ctx, httpClient, NumRetriesDefault, &ops.dxEnv,
fmt.Sprintf("%s/removeTags", objId),
string(payload))
if err != nil {
return err
}

var reply ReplyRemoveTags
if err := json.Unmarshal(repJs, &reply); err != nil {
return err
}

return nil
}
Loading

0 comments on commit 004d66f

Please sign in to comment.