fix(files): fix small issues
This commit is contained in:
parent
70318be81d
commit
fb9de35e81
2 changed files with 15 additions and 1 deletions
|
@ -25,6 +25,7 @@ type LocalFS struct {
|
||||||
opensMtx *sync.RWMutex
|
opensMtx *sync.RWMutex
|
||||||
opensCleanSize int
|
opensCleanSize int
|
||||||
openTTL time.Duration
|
openTTL time.Duration
|
||||||
|
readersMtx *sync.RWMutex
|
||||||
readers map[string]*fileInfo
|
readers map[string]*fileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ func NewLocalFS(root string, defaultPerm uint32, opensLimit, openTTL int) *Local
|
||||||
openTTL: time.Duration(openTTL) * time.Second,
|
openTTL: time.Duration(openTTL) * time.Second,
|
||||||
opensMtx: &sync.RWMutex{},
|
opensMtx: &sync.RWMutex{},
|
||||||
opensCleanSize: 10,
|
opensCleanSize: 10,
|
||||||
|
readersMtx: &sync.RWMutex{},
|
||||||
readers: map[string]*fileInfo{}, // TODO: track readers and close idles
|
readers: map[string]*fileInfo{}, // TODO: track readers and close idles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,6 +309,9 @@ func (fs *LocalFS) GetFileReader(path string) (fs.ReadCloseSeeker, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs.readersMtx.Lock()
|
||||||
|
defer fs.readersMtx.Unlock()
|
||||||
|
|
||||||
fs.readers[fullpath] = &fileInfo{
|
fs.readers[fullpath] = &fileInfo{
|
||||||
fd: fd,
|
fd: fd,
|
||||||
lastAccess: time.Now(),
|
lastAccess: time.Now(),
|
||||||
|
|
|
@ -158,7 +158,13 @@ func (h *FileHandlers) Create(c *gin.Context) {
|
||||||
err = h.deps.FS().Create(tmpFilePath)
|
err = h.deps.FS().Create(tmpFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsExist(err) {
|
if os.IsExist(err) {
|
||||||
|
// avoid adding file size more than once
|
||||||
|
err = h.deps.Users().SetUsed(userIDInt, false, req.FileSize)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(q.ErrResp(c, 500, err))
|
||||||
|
} else {
|
||||||
c.JSON(q.ErrResp(c, 304, err))
|
c.JSON(q.ErrResp(c, 304, err))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(q.ErrResp(c, 500, err))
|
c.JSON(q.ErrResp(c, 500, err))
|
||||||
}
|
}
|
||||||
|
@ -728,6 +734,9 @@ func (h *FileHandlers) ListUploadings(c *gin.Context) {
|
||||||
c.JSON(q.ErrResp(c, 500, err))
|
c.JSON(q.ErrResp(c, 500, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if infos == nil {
|
||||||
|
infos = []*UploadInfo{}
|
||||||
|
}
|
||||||
c.JSON(200, &ListUploadingsResp{UploadInfos: infos})
|
c.JSON(200, &ListUploadingsResp{UploadInfos: infos})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue