From 02b0a3b697267564e9fecc31062f87a12174c867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Tue, 19 Mar 2013 10:33:31 +0100 Subject: [PATCH] Remove old data code --- src/cmd/tusd/data.go | 78 -------------------------------------------- src/cmd/tusd/http.go | 2 +- 2 files changed, 1 insertion(+), 79 deletions(-) diff --git a/src/cmd/tusd/data.go b/src/cmd/tusd/data.go index 8727234..a751a06 100644 --- a/src/cmd/tusd/data.go +++ b/src/cmd/tusd/data.go @@ -3,14 +3,9 @@ package main // This is very simple for now and will be enhanced as needed. import ( - "errors" - "fmt" "io" - "io/ioutil" "os" "path" - "strconv" - "strings" ) var dataDir string @@ -35,79 +30,6 @@ func logPath(fileId string) string { return dataPath(fileId) + ".log" } -func putFileChunk(fileId string, start int64, end int64, r io.Reader) error { - d := dataPath(fileId) - file, err := os.OpenFile(d, os.O_WRONLY, 0666) - if err != nil { - return err - } - defer file.Close() - - if n, err := file.Seek(start, os.SEEK_SET); err != nil { - return err - } else if n != start { - return errors.New("putFileChunk: seek failure") - } - - size := end - start + 1 - if n, err := io.CopyN(file, r, size); err != nil { - return err - } else if n != size { - return errors.New("putFileChunk: partial copy") - } - - l := logPath(fileId) - logFile, err := os.OpenFile(l, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666) - if err != nil { - return err - } - defer logFile.Close() - - entry := fmt.Sprintf("%d,%d\n", start, end) - if _, err := logFile.WriteString(entry); err != nil { - return err - } - - return nil -} - -func getReceivedChunks(fileId string) (chunkSet, error) { - l := logPath(fileId) - // @TODO stream the file / limit log file size? - data, err := ioutil.ReadFile(l) - if err != nil { - return nil, err - } - lines := strings.Split(string(data), "\n") - - chunks := make(chunkSet, 0, len(lines)-1) - for i, line := range lines { - // last line is always empty, skip it - if lastLine := i+1 == len(lines); lastLine { - break - } - - parts := strings.Split(line, ",") - if len(parts) != 2 { - return nil, errors.New("getReceivedChunks: corrupt log line: " + line) - } - - start, err := strconv.ParseInt(parts[0], 10, 64) - if err != nil { - return nil, errors.New("getReceivedChunks: invalid start: " + parts[0]) - } - - end, err := strconv.ParseInt(parts[1], 10, 64) - if err != nil { - return nil, errors.New("getReceivedChunks: invalid end: " + parts[1]) - } - - chunks.Add(chunk{Start: start, End: end}) - } - - return chunks, nil -} - func getFileData(fileId string) (io.ReadCloser, int64, error) { d := dataPath(fileId) file, err := os.Open(d) diff --git a/src/cmd/tusd/http.go b/src/cmd/tusd/http.go index b06c2f1..10cab04 100644 --- a/src/cmd/tusd/http.go +++ b/src/cmd/tusd/http.go @@ -133,7 +133,7 @@ func putFile(w http.ResponseWriter, r *http.Request, fileId string) { // @TODO: Check that file exists // @TODO: Make sure contentRange.Size matches file size - if err := putFileChunk(fileId, contentRange.Start, contentRange.End, r.Body); err != nil { + if err := dataStore.WriteFileChunk(fileId, contentRange.Start, contentRange.End, r.Body); err != nil { // @TODO: Could be a 404 as well reply(w, http.StatusInternalServerError, err.Error()) return