Statistics
| Branch: | Tag: | Revision:

arvados / services / keep-web / webdav.go @ 654ee915

History | View | Annotate | Download (1.32 KB)

1
// Copyright (C) The Arvados Authors. All rights reserved.
2
//
3
// SPDX-License-Identifier: AGPL-3.0
4

    
5
package main
6

    
7
import (
8
	"errors"
9
	"net/http"
10
	"os"
11

    
12
	"golang.org/x/net/context"
13
	"golang.org/x/net/webdav"
14
)
15

    
16
var errReadOnly = errors.New("read-only filesystem")
17

    
18
// webdavFS implements a read-only webdav.FileSystem by wrapping
19
// http.Filesystem.
20
type webdavFS struct {
21
	httpfs http.FileSystem
22
}
23

    
24
var _ webdav.FileSystem = &webdavFS{}
25

    
26
func (fs *webdavFS) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
27
	return errReadOnly
28
}
29

    
30
func (fs *webdavFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
31
	f, err := fs.httpfs.Open(name)
32
	if err != nil {
33
		return nil, err
34
	}
35
	return &webdavFile{File: f}, nil
36
}
37

    
38
func (fs *webdavFS) RemoveAll(ctx context.Context, name string) error {
39
	return errReadOnly
40
}
41

    
42
func (fs *webdavFS) Rename(ctx context.Context, oldName, newName string) error {
43
	return errReadOnly
44
}
45

    
46
func (fs *webdavFS) Stat(ctx context.Context, name string) (os.FileInfo, error) {
47
	if f, err := fs.httpfs.Open(name); err != nil {
48
		return nil, err
49
	} else {
50
		return f.Stat()
51
	}
52
}
53

    
54
// webdavFile implements a read-only webdav.File by wrapping
55
// http.File. Writes fail.
56
type webdavFile struct {
57
	http.File
58
}
59

    
60
func (f *webdavFile) Write([]byte) (int, error) {
61
	return 0, errReadOnly
62
}