The following commit has been merged in the master branch:
commit c0c4c9a08fa25ba5d14ffbb7578cf28c3d978f2f
Author: Niels Thykier <[email protected]>
Date:   Sat Jun 16 14:00:05 2012 +0200

    L::Util: Fix truncation of file in touch_file
    
    So far this has not been an issue because all uses have only involved
    empty (or non-existent) files.
    
    Signed-off-by: Niels Thykier <[email protected]>

diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index f601335..d9714c7 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -759,11 +759,15 @@ the failure.
 
 =cut
 
-# create an empty file
-# --okay, okay, this is not exactly what `touch' does :-)
 sub touch_file {
-    open(T, '>', $_[0]) or return 0;
-    close(T) or return 0;
+    my ($file) = @_;
+    # We use '>>' because '>' truncates the file if it has contents
+    # (which `touch file` doesn't).
+    open my $fd, '>>', $file or return 0;
+    close $fd or return 0;
+    # open with '>>' does not update the mtime if the file already
+    # exists, so use utime to solve that.
+    utime undef, undef, $file or return 0;
 
     return 1;
 }

-- 
Debian package checker


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: http://lists.debian.org/[email protected]

Reply via email to