]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
printing: Make file_version_is_newer() more precise
authorVolker Lendecke <vl@samba.org>
Sun, 4 Jan 2026 10:23:56 +0000 (11:23 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2026 11:53:34 +0000 (11:53 +0000)
We have timespec_compare, we don't have to loose info.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/printing/nt_printing.c

index 8a37f4562024a731aa0874bb2f03be3d8ae29b3b..89f31a60406c97cdea87970162c4dec0f3f9660d 100644 (file)
@@ -804,24 +804,19 @@ static int file_version_is_newer(connection_struct *conn,
 
        uint32_t new_major;
        uint32_t new_minor;
-       time_t new_create_time;
+       struct stat_ex new_stat = {};
 
        uint32_t old_major;
        uint32_t old_minor;
-       time_t old_create_time;
+       struct stat_ex old_stat = {};
 
        struct smb_filename *smb_fname = NULL;
        files_struct    *fsp = NULL;
        struct files_struct *dirfsp = NULL;
-       SMB_STRUCT_STAT st;
 
        NTSTATUS status;
        int ret;
 
-       SET_STAT_INVALID(st);
-       new_create_time = (time_t)0;
-       old_create_time = (time_t)0;
-
        /* Get file version info (if available) for previous file (if it exists) */
        status = driver_unix_convert(conn, old_file, &dirfsp, &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
@@ -868,12 +863,13 @@ static int file_version_is_newer(connection_struct *conn,
                DBG_NOTICE("Version info not found [%s], use mod time\n",
                           old_file);
                use_version = false;
-               if (SMB_VFS_FSTAT(fsp, &st) == -1) {
+               if (SMB_VFS_FSTAT(fsp, &old_stat) == -1) {
                        goto error_exit;
                }
-               old_create_time = convert_timespec_to_time_t(st.st_ex_mtime);
                DBG_NOTICE("mod time = %s\n",
-                          timespec_string_buf(&st.st_ex_mtime, true, &buf));
+                          timespec_string_buf(&old_stat.st_ex_mtime,
+                                              true,
+                                              &buf));
        }
 
        close_file_free(NULL, &fsp, NORMAL_CLOSE);
@@ -923,12 +919,13 @@ static int file_version_is_newer(connection_struct *conn,
                DBG_INFO("Version info not found [%s], use mod time\n",
                         new_file);
                use_version = false;
-               if (SMB_VFS_FSTAT(fsp, &st) == -1) {
+               if (SMB_VFS_FSTAT(fsp, &new_stat) == -1) {
                        goto error_exit;
                }
-               new_create_time = convert_timespec_to_time_t(st.st_ex_mtime);
                DBG_NOTICE("mod time = %s\n",
-                          timespec_string_buf(&st.st_ex_mtime, true, &buf));
+                          timespec_string_buf(&new_stat.st_ex_mtime,
+                                              true,
+                                              &buf));
        }
 
        close_file_free(NULL, &fsp, NORMAL_CLOSE);
@@ -951,8 +948,9 @@ static int file_version_is_newer(connection_struct *conn,
                }
 
        } else {
-               /* Compare modification time/dates and choose the newest time/date */
-               if (new_create_time > old_create_time) {
+               int cmp = timespec_compare(&old_stat.st_ex_mtime,
+                                          &new_stat.st_ex_mtime);
+               if (cmp == -1) {
                        DBG_INFO("Replacing [%s] with [%s]\n",
                                 old_file,
                                 new_file);