mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-23 20:16:28 +08:00
finish delete
This commit is contained in:
@@ -255,12 +255,12 @@ func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
progress(19)
|
progress(19)
|
||||||
if file.Class == "" || strings.Contains(file.Class, "..") {
|
if file.Class == "" || strings.Contains(file.Class, "..") || strings.ContainsAny(file.Class, `/\`) {
|
||||||
return nil, ErrEmptyClass
|
return nil, ErrEmptyClass
|
||||||
}
|
}
|
||||||
filebasepath := ""
|
filebasepath := ""
|
||||||
if istemp {
|
if istemp {
|
||||||
filebasepath = PaperFolder + "temp/" + strconv.Itoa(*user.ID) + "/"
|
filebasepath = PaperFolder + "temp/" + strconv.Itoa(*user.ID) + "/" + file.Class + "/"
|
||||||
} else {
|
} else {
|
||||||
filebasepath = fmt.Sprintf(
|
filebasepath = fmt.Sprintf(
|
||||||
PaperFolder+file.Class+"/%v/%v/%v/%c/",
|
PaperFolder+file.Class+"/%v/%v/%v/%c/",
|
||||||
@@ -513,6 +513,13 @@ func (f *FileDatabase) DelFile(lstid, uid int, istemp bool) error {
|
|||||||
if lst.Path == "" || strings.Contains(lst.Path, "..") {
|
if lst.Path == "" || strings.Contains(lst.Path, "..") {
|
||||||
return os.ErrNotExist
|
return os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
err = f.db.Del(FileTableList, "WHERE ID="+strconv.Itoa(lstid))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if lst.HasntAnalyzed {
|
||||||
|
return os.RemoveAll(lst.Path)
|
||||||
|
}
|
||||||
i := strings.LastIndex(lst.Path, "/")
|
i := strings.LastIndex(lst.Path, "/")
|
||||||
if i <= 0 {
|
if i <= 0 {
|
||||||
return os.ErrNotExist
|
return os.ErrNotExist
|
||||||
@@ -521,25 +528,23 @@ func (f *FileDatabase) DelFile(lstid, uid int, istemp bool) error {
|
|||||||
if utils.IsNotExist(parentfolder) {
|
if utils.IsNotExist(parentfolder) {
|
||||||
return os.ErrNotExist
|
return os.ErrNotExist
|
||||||
}
|
}
|
||||||
if !lst.HasntAnalyzed {
|
f.mu.RLock()
|
||||||
f.mu.RLock()
|
file, err := sql.Find[File](&f.db, ftable, "WHERE ListID="+strconv.Itoa(lstid))
|
||||||
file, err := sql.Find[File](&f.db, ftable, "WHERE ListID="+strconv.Itoa(lstid))
|
f.mu.RUnlock()
|
||||||
f.mu.RUnlock()
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
}
|
err = f.db.Del(ftable, "WHERE ListID="+strconv.Itoa(lstid))
|
||||||
err = f.db.Del(ftable, "WHERE ListID="+strconv.Itoa(lstid))
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
}
|
ques := make([]QuestionJSON, 0, 64)
|
||||||
ques := make([]QuestionJSON, 0, 64)
|
err = json.Unmarshal(file.Questions, &ques)
|
||||||
err = json.Unmarshal(file.Questions, &ques)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
}
|
for _, q := range ques {
|
||||||
for _, q := range ques {
|
q.Delete(f, istemp)
|
||||||
q.Delete(f, istemp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return os.RemoveAll(parentfolder)
|
return os.RemoveAll(parentfolder)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user