Skip to content

Commit 7e26981

Browse files
authored
Update dir attributes (#72)
1 parent 9c89f96 commit 7e26981

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

pkg/dataplane/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ type Container interface {
6161
// PutObjectSync
6262
PutObjectSync(*PutObjectInput) error
6363

64+
// UpdateObjectSync
65+
UpdateObjectSync(*UpdateObjectInput) error
66+
6467
// DeleteObject
6568
DeleteObject(*DeleteObjectInput, interface{}, chan *Response) (*Request, error)
6669

pkg/dataplane/http/container.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ func (c *container) PutObjectSync(putObjectInput *v3io.PutObjectInput) error {
128128
return c.session.context.PutObjectSync(putObjectInput)
129129
}
130130

131+
// UpdateObjectSync
132+
func (c *container) UpdateObjectSync(updateObjectInput *v3io.UpdateObjectInput) error {
133+
c.populateInputFields(&updateObjectInput.DataPlaneInput)
134+
return c.session.context.UpdateObjectSync(updateObjectInput)
135+
}
136+
131137
// DeleteObject
132138
func (c *container) DeleteObject(deleteObjectInput *v3io.DeleteObjectInput,
133139
context interface{},

pkg/dataplane/http/context.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,28 @@ func (c *context) PutObjectSync(putObjectInput *v3io.PutObjectInput) error {
563563
return err
564564
}
565565

566+
// UpdateObjectSync
567+
func (c *context) UpdateObjectSync(updateObjectInput *v3io.UpdateObjectInput) error {
568+
headers := map[string]string{
569+
"X-v3io-function": "DirSetAttr",
570+
}
571+
572+
marshaledDirAttributes, err := json.Marshal(updateObjectInput.DirAttributes)
573+
if err != nil {
574+
return err
575+
}
576+
577+
_, err = c.sendRequest(&updateObjectInput.DataPlaneInput,
578+
http.MethodPut,
579+
updateObjectInput.Path,
580+
"",
581+
headers,
582+
marshaledDirAttributes,
583+
true)
584+
585+
return err
586+
}
587+
566588
// DeleteObject
567589
func (c *context) DeleteObject(deleteObjectInput *v3io.DeleteObjectInput,
568590
context interface{},

pkg/dataplane/test/sync_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"fmt"
5+
"strconv"
56
"testing"
67
"time"
78

@@ -209,6 +210,77 @@ func (suite *syncContainerTestSuite) TestGetContainerContentsDirsWithAllAttrs()
209210
}
210211
}
211212

213+
func (suite *syncContainerTestSuite) TestSetDirsAttrs() {
214+
path := fmt.Sprintf("tmp/test/sync_test/TestSetDirsAttrs/%d/", time.Now().Unix())
215+
216+
// create empty directory
217+
putObjectInput := &v3io.PutObjectInput{}
218+
putObjectInput.Path = fmt.Sprintf("%sdir-test/", path)
219+
putObjectInput.Body = nil
220+
221+
// when run against a context
222+
suite.populateDataPlaneInput(&putObjectInput.DataPlaneInput)
223+
err := suite.container.PutObjectSync(putObjectInput)
224+
suite.Require().NoError(err, "Failed to create test directory")
225+
226+
// Update directory's attributes
227+
updateObjectInput := &v3io.UpdateObjectInput{}
228+
updateObjectInput.Path = fmt.Sprintf("%sdir-test/", path)
229+
layout := "2006-01-02T15:04:05.00Z"
230+
atime, err := time.Parse(layout, "2020-11-22T19:27:33.49Z")
231+
suite.Require().NoError(err)
232+
ctime, err := time.Parse(layout, "2020-09-20T15:10:35.08Z")
233+
suite.Require().NoError(err)
234+
mtime, err := time.Parse(layout, "2020-09-24T12:55:35.08Z")
235+
suite.Require().NoError(err)
236+
dirAttributes := &v3io.DirAttributes{
237+
Mode: 511,
238+
UID: 67,
239+
GID: 68,
240+
AtimeSec: int(atime.Unix()),
241+
AtimeNSec: int(atime.UnixNano() % 1000000000),
242+
CtimeSec: int(ctime.Unix()),
243+
CtimeNSec: int(ctime.UnixNano() % 1000000000),
244+
MtimeSec: int(mtime.Unix()),
245+
MtimeNSec: int(mtime.UnixNano() % 1000000000),
246+
}
247+
updateObjectInput.DirAttributes = dirAttributes
248+
249+
// when run against a context
250+
suite.populateDataPlaneInput(&updateObjectInput.DataPlaneInput)
251+
err = suite.container.UpdateObjectSync(updateObjectInput)
252+
suite.Require().NoError(err, "Failed to update test directory")
253+
254+
// Read directory and compare attributes
255+
getContainerContentsInput := v3io.GetContainerContentsInput{
256+
Path: path,
257+
GetAllAttributes: true,
258+
DirectoriesOnly: true,
259+
Limit: 10,
260+
}
261+
262+
// when run against a context
263+
suite.populateDataPlaneInput(&getContainerContentsInput.DataPlaneInput)
264+
265+
// get container contents
266+
response, err := suite.container.GetContainerContentsSync(&getContainerContentsInput)
267+
suite.Require().NoError(err, "Failed to get container contents")
268+
response.Release()
269+
270+
getContainerContentsOutput := response.Output.(*v3io.GetContainerContentsOutput)
271+
suite.Require().Empty(len(getContainerContentsOutput.Contents))
272+
suite.Require().Equal(1, len(getContainerContentsOutput.CommonPrefixes))
273+
suite.Require().Equal(false, getContainerContentsOutput.IsTruncated)
274+
275+
prefix := getContainerContentsOutput.CommonPrefixes[0]
276+
suite.Require().Equal(atime.Format(layout), prefix.AccessTime)
277+
suite.Require().Equal(mtime.Format(layout), prefix.LastModified)
278+
suite.Require().Equal(ctime.Format(layout), prefix.CreatingTime)
279+
suite.Require().Equal(strconv.FormatInt(int64(dirAttributes.GID), 16), prefix.GID)
280+
suite.Require().Equal(strconv.FormatInt(int64(dirAttributes.UID), 16), prefix.UID)
281+
suite.Require().Equal("040777", string(prefix.Mode))
282+
}
283+
212284
type syncContextContainerTestSuite struct {
213285
syncContainerTestSuite
214286
}

pkg/dataplane/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ type DeleteObjectInput struct {
201201
Path string
202202
}
203203

204+
type UpdateObjectInput struct {
205+
DataPlaneInput
206+
Path string
207+
DirAttributes *DirAttributes
208+
}
209+
210+
type DirAttributes struct {
211+
Mode int `json:"mode,omitempty"`
212+
UID int `json:"uid,omitempty"`
213+
GID int `json:"gid,omitempty"`
214+
AtimeSec int `json:"atime.sec,omitempty"`
215+
AtimeNSec int `json:"atime.nsec,omitempty"`
216+
CtimeSec int `json:"ctime.sec,omitempty"`
217+
CtimeNSec int `json:"ctime.nsec,omitempty"`
218+
MtimeSec int `json:"mtime.sec,omitempty"`
219+
MtimeNSec int `json:"mtime.nsec,omitempty"`
220+
}
221+
204222
//
205223
// KV
206224
//

0 commit comments

Comments
 (0)