Browse Source

Fix dyreshark breakages + fix small file with no extension bug

pull/49/head
andreimarcu 9 years ago
parent
commit
11039d57f1
  1. 4
      expiry.go
  2. 2
      meta.go
  3. 9
      upload.go

4
expiry.go

@ -4,10 +4,12 @@ import (
"time"
)
var neverExpire = time.Unix(0, 0)
// Determine if a file with expiry set to "ts" has expired yet
func isTsExpired(ts time.Time) bool {
now := time.Now()
return !ts.IsZero() && now.After(ts)
return ts != neverExpire && now.After(ts)
}
// Determine if the given filename is expired

2
meta.go

@ -23,7 +23,7 @@ func metadataWrite(filename string, upload *Upload) error {
w := bufio.NewWriter(file)
fmt.Fprintln(w, upload.Expiry)
fmt.Fprintln(w, upload.Expiry.Unix())
fmt.Fprintln(w, upload.DeleteKey)
return w.Flush()

9
upload.go

@ -199,8 +199,8 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
if len(extension) == 0 {
// Pull the first 512 bytes off for use in MIME detection
header = make([]byte, 512)
n, err := upReq.src.Read(header)
if n == 0 || err != nil {
n, _ := upReq.src.Read(header)
if n == 0 {
return upload, errors.New("Empty file")
}
header = header[:n]
@ -246,7 +246,10 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
defer dst.Close()
// Get the rest of the metadata needed for storage
if upReq.expiry != 0 {
if upReq.expiry == 0 {
upload.Expiry = neverExpire
} else {
upload.Expiry = time.Now().Add(upReq.expiry)
}

Loading…
Cancel
Save