projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
18870: Need to declare NODES as array
[arvados.git]
/
services
/
keep-web
/
webdav.go
diff --git
a/services/keep-web/webdav.go
b/services/keep-web/webdav.go
index af83681f9c4b435285ebe1e6f3b9c1a1f7a807a4..501c355a7388a53fe3b40fc3f082c63768665620 100644
(file)
--- a/
services/keep-web/webdav.go
+++ b/
services/keep-web/webdav.go
@@
-2,7
+2,7
@@
//
// SPDX-License-Identifier: AGPL-3.0
//
// SPDX-License-Identifier: AGPL-3.0
-package
main
+package
keepweb
import (
"crypto/rand"
import (
"crypto/rand"
@@
-16,7
+16,7
@@
import (
"sync/atomic"
"time"
"sync/atomic"
"time"
- "git.
curoverse.com
/arvados.git/sdk/go/arvados"
+ "git.
arvados.org
/arvados.git/sdk/go/arvados"
"golang.org/x/net/context"
"golang.org/x/net/webdav"
"golang.org/x/net/context"
"golang.org/x/net/webdav"
@@
-36,7
+36,7
@@
var (
// existence automatically so sequences like "mkcol foo; put foo/bar"
// work as expected.
type webdavFS struct {
// existence automatically so sequences like "mkcol foo; put foo/bar"
// work as expected.
type webdavFS struct {
- collfs arvados.
Collection
FileSystem
+ collfs arvados.FileSystem
writing bool
// webdav PROPFIND reads the first few bytes of each file
// whose filename extension isn't recognized, which is
writing bool
// webdav PROPFIND reads the first few bytes of each file
// whose filename extension isn't recognized, which is
@@
-47,7
+47,10
@@
type webdavFS struct {
}
func (fs *webdavFS) makeparents(name string) {
}
func (fs *webdavFS) makeparents(name string) {
- dir, name := path.Split(name)
+ if !fs.writing {
+ return
+ }
+ dir, _ := path.Split(name)
if dir == "" || dir == "/" {
return
}
if dir == "" || dir == "/" {
return
}
@@
-66,7
+69,7
@@
func (fs *webdavFS) Mkdir(ctx context.Context, name string, perm os.FileMode) er
}
func (fs *webdavFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (f webdav.File, err error) {
}
func (fs *webdavFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (f webdav.File, err error) {
- writing := flag&(os.O_WRONLY|os.O_RDWR) != 0
+ writing := flag&(os.O_WRONLY|os.O_RDWR
|os.O_TRUNC
) != 0
if writing {
fs.makeparents(name)
}
if writing {
fs.makeparents(name)
}
@@
-75,8
+78,13
@@
func (fs *webdavFS) OpenFile(ctx context.Context, name string, flag int, perm os
// webdav module returns 404 on all OpenFile errors,
// but returns 405 Method Not Allowed if OpenFile()
// succeeds but Write() or Close() fails. We'd rather
// webdav module returns 404 on all OpenFile errors,
// but returns 405 Method Not Allowed if OpenFile()
// succeeds but Write() or Close() fails. We'd rather
- // have 405.
- f = writeFailer{File: f, err: errReadOnly}
+ // have 405. writeFailer ensures Close() fails if the
+ // file is opened for writing *or* Write() is called.
+ var err error
+ if writing {
+ err = errReadOnly
+ }
+ f = writeFailer{File: f, err: err}
}
if fs.alwaysReadEOF {
f = readEOF{File: f}
}
if fs.alwaysReadEOF {
f = readEOF{File: f}
@@
-92,6
+100,11
@@
func (fs *webdavFS) Rename(ctx context.Context, oldName, newName string) error {
if !fs.writing {
return errReadOnly
}
if !fs.writing {
return errReadOnly
}
+ if strings.HasSuffix(oldName, "/") {
+ // WebDAV "MOVE foo/ bar/" means rename foo to bar.
+ oldName = oldName[:len(oldName)-1]
+ newName = strings.TrimSuffix(newName, "/")
+ }
fs.makeparents(newName)
return fs.collfs.Rename(oldName, newName)
}
fs.makeparents(newName)
return fs.collfs.Rename(oldName, newName)
}
@@
-109,10
+122,15
@@
type writeFailer struct {
}
func (wf writeFailer) Write([]byte) (int, error) {
}
func (wf writeFailer) Write([]byte) (int, error) {
+ wf.err = errReadOnly
return 0, wf.err
}
func (wf writeFailer) Close() error {
return 0, wf.err
}
func (wf writeFailer) Close() error {
+ err := wf.File.Close()
+ if err != nil {
+ wf.err = err
+ }
return wf.err
}
return wf.err
}