Skip to content

Commit

Permalink
httpfs: touch method
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Jan 7, 2015
1 parent 8233950 commit 7762d89
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 30 additions & 0 deletions httpfs/httpfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ func Mkdir(URL string) error {
}
}

func Touch(URL string) error {
URL = cleanup(URL)
if isRemote(URL) {
return httpTouch(URL)
} else {
return localTouch(URL)
}
}

func ReadDir(URL string) ([]string, error) {
URL = cleanup(URL)
if isRemote(URL) {
Expand Down Expand Up @@ -120,6 +129,7 @@ const (
PUT action = "put"
READ action = "read"
RM action = "rm"
TOUCH action = "touch"
)

// server-side
Expand All @@ -132,6 +142,7 @@ func Handle() {
PUT: handlePut,
READ: handleRead,
RM: handleRemove,
TOUCH: handleTouch,
}
for k, v := range m {
http.HandleFunc("/"+string(k)+"/", newHandler(k, v))
Expand Down Expand Up @@ -187,6 +198,10 @@ func handleMkdir(fname string, data []byte, w io.Writer) error {
return localMkdir(fname)
}

func handleTouch(fname string, data []byte, w io.Writer) error {
return localTouch(fname)
}

func handleRead(fname string, data []byte, w io.Writer) error {
b, err := localRead(fname)
if err != nil {
Expand Down Expand Up @@ -240,6 +255,11 @@ func httpMkdir(URL string) error {
return err
}

func httpTouch(URL string) error {
_, err := do(TOUCH, URL, nil)
return err
}

func httpLs(URL string) (ls []string, err error) {
r, errHTTP := do(LS, URL, nil)
if errHTTP != nil {
Expand Down Expand Up @@ -279,6 +299,16 @@ func localMkdir(fname string) error {
return os.MkdirAll(fname, DirPerm)
}

func localTouch(fname string) error {
lock.Lock()
defer lock.Unlock()
f, err := os.Create(fname)
if err != nil {
f.Close()
}
return err
}

func localLs(fname string) ([]string, error) {
lock.Lock()
defer lock.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions httpfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func MustOpen(URL string) io.ReadCloser {
return f
}

func Touch(URL string) error {
return Append(URL, []byte{})
}
//func Touch(URL string) error {
// return Append(URL, []byte{})
//}

type bufWriter struct {
buf *bufio.Writer
Expand Down

0 comments on commit 7762d89

Please sign in to comment.