[tracker-miners/wip/carlosg/coverity-fixes: 23/28] tracker-writeback: Check return values of g_file_move/delete




commit 88ca75472d8338260279930d11ec2e3919eb0a3f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Oct 24 12:19:17 2021 +0200

    tracker-writeback: Check return values of g_file_move/delete
    
    After writing back metadata (or failing to), we forget to check
    the result of the operations to replace/delete the file.
    
    CID: #365689

 src/tracker-writeback/tracker-writeback-file.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-file.c b/src/tracker-writeback/tracker-writeback-file.c
index 59a97f7e4..b6d1be582 100644
--- a/src/tracker-writeback/tracker-writeback-file.c
+++ b/src/tracker-writeback/tracker-writeback-file.c
@@ -256,15 +256,24 @@ tracker_writeback_file_write_metadata (TrackerWriteback  *writeback,
                                                              &n_error);
 
        if (!retval) {
+               GError *inner_error = NULL;
+
                /* Delete the temporary file and preserve original */
-               g_file_delete (tmp_file, NULL, NULL);
+               if (!g_file_delete (tmp_file, NULL, &inner_error) &&
+                   !g_error_matches (inner_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
+                       g_warning ("Failed to delete temporary file: %s", inner_error->message);
+               }
+
+               g_clear_error (&inner_error);
        } else {
                /* Move back the modified file to the original location. Correct UNIX
                 * mode has been set for tmp_file in create_temporary_file() already.
                 */
-               g_file_move (tmp_file, file,
-                            G_FILE_COPY_OVERWRITE,
-                            NULL, NULL, NULL, NULL);
+               if (!g_file_move (tmp_file, file,
+                                 G_FILE_COPY_OVERWRITE,
+                                 NULL, NULL, NULL, &n_error)) {
+                       g_warning ("Failed to replace file: %s", n_error->message);
+               }
        }
 
        g_object_unref (file_info);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]