Creating parent collection method was added (#22)
* method for creating parent collection was added to Client struct "func (c *Client) createParentCollection(itemPath string) error" was added to request.go file * using Client's method to create parent collection in following methods: Client.Write() Client.WriteStream() Client.copymove() deadlock is impossible in method Client.copymove() because of paragraph #6 section 9.8.5 (https://tools.ietf.org/html/rfc4918#section-9.8.5) and paragraph #6 section 9.9.4 (https://tools.ietf.org/html/rfc4918#section-9.9.4) of RFC 4918 (https://tools.ietf.org/html/rfc4918) * install dependencies script was added to Travis-CI file * testing was added to Travis-CI file * error wrapping was removed from Client.put() method * using an early return on error in case of 409 in Client.Write() method
This commit is contained in:
committed by
Christoph Polcin
parent
28039fda22
commit
83e3d1e31e
23
client.go
23
client.go
@@ -346,13 +346,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
||||
return nil
|
||||
|
||||
case 409:
|
||||
if i := strings.LastIndex(path, "/"); i > -1 {
|
||||
if err := c.MkdirAll(path[0:i+1], 0755); err == nil {
|
||||
s = c.put(path, bytes.NewReader(data))
|
||||
if s == 200 || s == 201 || s == 204 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
err := c.createParentCollection(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s = c.put(path, bytes.NewReader(data))
|
||||
if s == 200 || s == 201 || s == 204 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,8 +362,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) error {
|
||||
|
||||
// WriteStream writes a stream
|
||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error {
|
||||
// TODO check if parent collection exists
|
||||
|
||||
err := c.createParentCollection(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s := c.put(path, stream)
|
||||
|
||||
switch s {
|
||||
case 200, 201, 204:
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user