develooper Front page | perl.perl5.porters | Postings from September 2012

[perl #114818] Replace unlink with unlink_all

Thread Previous
From:
Brad Gilbert
Date:
September 9, 2012 21:03
Subject:
[perl #114818] Replace unlink with unlink_all
Message ID:
rt-3.6.HEAD-11172-1347244004-431.114818-75-0@perl.org
# New Ticket Created by  "Brad Gilbert" 
# Please include the string:  [perl #114818]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=114818 >


I've looked for tests that require test.pl that use unlink(), and
replaced many of them with unlink_all()

unlink_all() is effectively the same as 1 while unlink() except with a
diagnostic if it fails

I have more changes to submit, but I wanted to get the obvious changes in first.

I removed unlink() from t/win32/fs.t because it was already getting
cleaned up by tempfile() in test.pl

Example patch:


>From 6cdfa8e60ef6dd11f3bba6c7f9a247960a4d2fd8 Mon Sep 17 00:00:00 2001
From: Brad Gilbert <b2gills@gmail.com>
Date: Sun, 9 Sep 2012 20:08:44 -0500
Subject: [PATCH 1/6] Replace unlink() with unlink_all() in t/io/fs.t

---
 t/io/fs.t |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/io/fs.t b/t/io/fs.t
index 26208c1..09af1b2 100644
--- a/t/io/fs.t
+++ b/t/io/fs.t
@@ -301,7 +301,7 @@ is(unlink('b'), 1, "unlink b");
 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
     $blksize,$blocks) = stat('b');
 is($ino, undef, "ino of unlinked file b should be undef");
-unlink 'c';
+unlink_all 'c';

 chdir $wd || die "Can't cd back to $wd";

@@ -322,8 +322,7 @@ SKIP: {
     is(symlink("TEST$$","c"), 1, "symlink");
     $foo = `grep perl c 2>&1`;
     ok($foo, "found perl in c");
-    unlink 'c';
-    unlink("TEST$$");
+    unlink_all('c',"TEST$$");
 }

 my $tmpfile = tempfile();
@@ -414,7 +413,7 @@ SKIP: {
 	close FH or die "close $n: $!";
 	eval "truncate $n, 0; 1" or die;
 	ok !-z $n, 'truncate(word) does not fall back to file name';
-	unlink $n;
+	unlink_all $n;
     }
 }

-- 
1.7.9.5

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About