|
|
|
@ -61,7 +61,7 @@ func (s SwampFileService) getOrCreateNs(namespace_in string) *namespace.Namespac
|
|
|
|
|
func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, size int64) error {
|
|
|
|
|
ns := s.getOrCreateNs(ref.UserAgent)
|
|
|
|
|
|
|
|
|
|
err := ref.Clean(true)
|
|
|
|
|
r, err := ref.Clean(true)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -71,7 +71,7 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
return namespace.ErrExceedQuota
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f, err := s.swamp_file_repo.Create(ref.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
f, err := s.swamp_file_repo.Create(r.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -80,7 +80,7 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
written, err := io.CopyN(f, src, size)
|
|
|
|
|
|
|
|
|
|
if written < size {
|
|
|
|
|
s.swamp_file_repo.Delete(ref.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
s.swamp_file_repo.Delete(r.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
return swampfile.ErrContentSizeExaggerated
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -89,12 +89,16 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
overread, err := src.Read(buf)
|
|
|
|
|
|
|
|
|
|
if overread > 0 || err != io.EOF {
|
|
|
|
|
s.swamp_file_repo.Delete(ref.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
s.swamp_file_repo.Delete(r.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
return swampfile.ErrContentSizeExceeded
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f.Close()
|
|
|
|
|
ns.FileQuota.Add(size)
|
|
|
|
|
uq, err := ns.FileQuota.Add(size)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
ns.FileQuota = *uq
|
|
|
|
|
ns.Usage = ns.Usage.Add(size)
|
|
|
|
|
ns.Upload = ns.Upload.Add(size)
|
|
|
|
|
s.namespace_repo.Update(ns.ID, *ns)
|
|
|
|
@ -105,13 +109,13 @@ func (s SwampFileService) SaveFile(ref swampfile.FileReference, src io.Reader, s
|
|
|
|
|
func (s SwampFileService) OpenOutFile(ref swampfile.FileReference) (swampfile.SwampOutFile, error) {
|
|
|
|
|
ns := s.getOrCreateNs(ref.UserAgent)
|
|
|
|
|
|
|
|
|
|
err := ref.Clean(true)
|
|
|
|
|
r, err := ref.Clean(true)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f, err := s.swamp_file_repo.Open(ref.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
f, err := s.swamp_file_repo.Open(r.Path, strconv.FormatInt(ns.ID, 10))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -140,7 +144,11 @@ func (s SwampFileService) CleanUpExpiredFiles() error {
|
|
|
|
|
dfs, err := s.swamp_file_repo.DeleteOlderThan(strconv.FormatInt(ns.ID, 10), expiry)
|
|
|
|
|
|
|
|
|
|
for _, df := range dfs {
|
|
|
|
|
ns.FileQuota.Remove(df.Size)
|
|
|
|
|
dq, err := ns.FileQuota.Remove(df.Size)
|
|
|
|
|
if err != nil {
|
|
|
|
|
dq.CurrentUsage = 0
|
|
|
|
|
}
|
|
|
|
|
ns.FileQuota = *dq
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|