fix(background): when list background is removed, delete file from file system and DB #1372

Merged
konrad merged 1 commits from :main into main 2023-02-01 11:38:24 +00:00

1 Commits

Author SHA1 Message Date
testinho.testador d74fdb35d1 fix(background): when list background is removed, delete file from file system and DB
continuous-integration/drone/pr Build is passing Details
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: [source](726a517bec/pkg/modules/background/upload/upload.go (L56-L62))

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
```
2023-01-31 19:21:57 -03:00