1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-17 10:56:24 -07:00

Fix deleted uploads not being unlinked when the post is edited

This commit is contained in:
Eggbertx 2022-12-17 17:28:31 -08:00
parent f7ca807144
commit 92924db1eb
2 changed files with 13 additions and 11 deletions

View file

@ -154,7 +154,7 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
}
documentRoot := config.GetSystemCriticalConfig().DocumentRoot
var filePath, thumbPath, catalogThumbPath string
if oldUpload != nil && oldUpload.Filename != "deleted" {
if oldUpload != nil {
filePath = path.Join(documentRoot, board.Dir, "src", oldUpload.Filename)
thumbPath = path.Join(documentRoot, board.Dir, "thumb", oldUpload.ThumbnailPath("thumb"))
catalogThumbPath = path.Join(documentRoot, board.Dir, "thumb", oldUpload.ThumbnailPath("catalog"))
@ -163,12 +163,15 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
serverutil.ServeError(writer, "Error unlinking old upload from post: "+err.Error(), wantsJSON, nil)
return
}
os.Remove(filePath)
os.Remove(thumbPath)
if post.IsTopPost {
os.Remove(catalogThumbPath)
if oldUpload.Filename != "deleted" {
os.Remove(filePath)
os.Remove(thumbPath)
if post.IsTopPost {
os.Remove(catalogThumbPath)
}
}
}
if err = post.AttachFile(upload); err != nil {
errEv.Err(err).Caller().
Str("newFilename", upload.Filename).

View file

@ -42,17 +42,16 @@ func getRecentPosts() ([]recentPost, error) {
SELECT id, board_id FROM DBPREFIXthreads
) t ON t.id = DBPREFIXposts.thread_id
LEFT JOIN (
select post_id, COALESCE(filename,'') as filename FROM DBPREFIXfiles
SELECT post_id, filename FROM DBPREFIXfiles
) f on f.post_id = DBPREFIXposts.id
INNER JOIN (
SELECT
id, thread_id FROM DBPREFIXposts WHERE is_top_post
SELECT id, thread_id FROM DBPREFIXposts WHERE is_top_post
) op ON op.thread_id = DBPREFIXposts.thread_id
WHERE DBPREFIXposts.is_deleted = FALSE`
if !siteCfg.RecentPostsWithNoFile {
query += ` AND f.filename != '' AND f.filename != 'deleted'`
}
query += ` LIMIT ` + strconv.Itoa(siteCfg.MaxRecentPosts)
query += " GROUP BY DBPREFIXposts.id LIMIT " + strconv.Itoa(siteCfg.MaxRecentPosts)
rows, err := gcsql.QuerySQL(query)
if err != nil {
return nil, err
@ -173,7 +172,7 @@ func BuildJS() error {
gcutil.LogError(err).
Str("building", "consts.js").
Str("filePath", constsJSPath).Send()
return fmt.Errorf("Error opening %q for writing: %s", constsJSPath, err.Error())
return fmt.Errorf("error opening %q for writing: %s", constsJSPath, err.Error())
}
defer constsJSFile.Close()
@ -188,7 +187,7 @@ func BuildJS() error {
gcutil.LogError(err).
Str("building", "consts.js").
Str("filePath", constsJSPath).Send()
return fmt.Errorf("Error building %q: %s", constsJSPath, err.Error())
return fmt.Errorf("error building %q: %s", constsJSPath, err.Error())
}
return nil
}