[PR #64] [CLOSED] WIP: fix(background): when list background is removed, delete file from file system and DB #4153

Closed
opened 2026-04-16 12:52:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/64
Author: @ceroma
Created: 1/26/2023
Status: Closed

Base: mainHead: background


📝 Commits (1)

  • 884dc3a fix(background): when list background is removed, delete file from file system and DB

📊 Changes

6 files changed (+112 additions, -17 deletions)

View changed files

📝 pkg/db/fixtures/lists.yml (+11 -0)
📝 pkg/files/files.go (+1 -1)
📝 pkg/models/list.go (+21 -0)
📝 pkg/models/list_test.go (+71 -11)
📝 pkg/modules/background/handler/background.go (+5 -0)
📝 pkg/modules/background/upload/upload.go (+3 -5)

📄 Description

Currently, if a list background is removed, the background file stays in disk and in the DB forever.

Fix this by deleting the file during background removal, similar to how it's done when a new background is uploaded.

Test Plan:
A) Before these changes
A.1) Create a new list
A.2) Set a new background to the list
A.3) Check file is in disk and DB:

$ ls files/
1

$ sqlite3 vikunja.db
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> select * from files;
1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1
sqlite> select * from lists;
1|Teste||||1|1|0|1|LeGlCmIqR*of_4R+WCoe4;s.oLjZ|65536.0|2023-01-25 21:25:21|2023-01-25 21:25:28

A.4) Remove background from list
A.5) Check file is still in disk and DB:

$ ls files/
1

$ sqlite3 vikunja.db
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> select * from files;
1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1
sqlite> select * from lists;
1|Teste||||1|1|0|0||65536.0|2023-01-25 21:25:21|2023-01-25 21:32:39

B) After these changes
B.1) Set background again
B.2) Check files in disk and DB:

$ ls files/
1 2

$ sqlite3 vikunja.db
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> select * from files;
1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1
2|20220410_180833.jpg||2822966|2023-01-25 21:34:33|1
sqlite> select * from lists;
1|Teste||||1|1|0|2|LeGlCmIqR*of_4R+WCoe4;s.oLjZ|65536.0|2023-01-25 21:25:21|2023-01-25 21:34:33

B.3) Remove background image
B.4) Check files and DB again, verify image 2 has been deleted:

$ ls files/
1

$ sqlite3 vikunja.db
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> select * from files;
1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1
sqlite> select * from lists;
1|Teste||||1|1|0|0||65536.0|2023-01-25 21:25:21|2023-01-25 21:36:13

C) Run unit tests:

$ mage test:unit

...

=== RUN   TestList_DeleteBackgroundFileIfExists
=== RUN   TestList_DeleteBackgroundFileIfExists/list_with_background
=== RUN   TestList_DeleteBackgroundFileIfExists/list_with_invalid_background
=== RUN   TestList_DeleteBackgroundFileIfExists/list_without_background
--- PASS: TestList_DeleteBackgroundFileIfExists (0.01s)
    --- PASS: TestList_DeleteBackgroundFileIfExists/list_with_background (0.00s)
    --- PASS: TestList_DeleteBackgroundFileIfExists/list_with_invalid_background (0.00s)
    --- PASS: TestList_DeleteBackgroundFileIfExists/list_without_background (0.00s)

...


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/64 **Author:** [@ceroma](https://github.com/ceroma) **Created:** 1/26/2023 **Status:** ❌ Closed **Base:** `main` ← **Head:** `background` --- ### 📝 Commits (1) - [`884dc3a`](https://github.com/go-vikunja/vikunja/commit/884dc3a4654fc6885df050aa23590cd7ea41e446) fix(background): when list background is removed, delete file from file system and DB ### 📊 Changes **6 files changed** (+112 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `pkg/db/fixtures/lists.yml` (+11 -0) 📝 `pkg/files/files.go` (+1 -1) 📝 `pkg/models/list.go` (+21 -0) 📝 `pkg/models/list_test.go` (+71 -11) 📝 `pkg/modules/background/handler/background.go` (+5 -0) 📝 `pkg/modules/background/upload/upload.go` (+3 -5) </details> ### 📄 Description Currently, if a list background is removed, the background file stays in disk and in the DB forever. Fix this by deleting the file during background removal, similar to how it's done when a new background is uploaded. Test Plan: A) Before these changes A.1) Create a new list A.2) Set a new background to the list A.3) Check file is in disk and DB: ``` $ ls files/ 1 $ sqlite3 vikunja.db SQLite version 3.40.1 2022-12-28 14:03:47 Enter ".help" for usage hints. sqlite> select * from files; 1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1 sqlite> select * from lists; 1|Teste||||1|1|0|1|LeGlCmIqR*of_4R+WCoe4;s.oLjZ|65536.0|2023-01-25 21:25:21|2023-01-25 21:25:28 ``` A.4) Remove background from list A.5) Check file is still in disk and DB: ``` $ ls files/ 1 $ sqlite3 vikunja.db SQLite version 3.40.1 2022-12-28 14:03:47 Enter ".help" for usage hints. sqlite> select * from files; 1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1 sqlite> select * from lists; 1|Teste||||1|1|0|0||65536.0|2023-01-25 21:25:21|2023-01-25 21:32:39 ``` B) After these changes B.1) Set background again B.2) Check files in disk and DB: ``` $ ls files/ 1 2 $ sqlite3 vikunja.db SQLite version 3.40.1 2022-12-28 14:03:47 Enter ".help" for usage hints. sqlite> select * from files; 1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1 2|20220410_180833.jpg||2822966|2023-01-25 21:34:33|1 sqlite> select * from lists; 1|Teste||||1|1|0|2|LeGlCmIqR*of_4R+WCoe4;s.oLjZ|65536.0|2023-01-25 21:25:21|2023-01-25 21:34:33 ``` B.3) Remove background image B.4) Check files and DB again, verify image 2 has been deleted: ``` $ ls files/ 1 $ sqlite3 vikunja.db SQLite version 3.40.1 2022-12-28 14:03:47 Enter ".help" for usage hints. sqlite> select * from files; 1|20220410_180833.jpg||2822966|2023-01-25 21:25:28|1 sqlite> select * from lists; 1|Teste||||1|1|0|0||65536.0|2023-01-25 21:25:21|2023-01-25 21:36:13 ``` C) Run unit tests: ``` $ mage test:unit ... === RUN TestList_DeleteBackgroundFileIfExists === RUN TestList_DeleteBackgroundFileIfExists/list_with_background === RUN TestList_DeleteBackgroundFileIfExists/list_with_invalid_background === RUN TestList_DeleteBackgroundFileIfExists/list_without_background --- PASS: TestList_DeleteBackgroundFileIfExists (0.01s) --- PASS: TestList_DeleteBackgroundFileIfExists/list_with_background (0.00s) --- PASS: TestList_DeleteBackgroundFileIfExists/list_with_invalid_background (0.00s) --- PASS: TestList_DeleteBackgroundFileIfExists/list_without_background (0.00s) ... ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 12:52:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#4153