summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@ens-lyon.org>2012-02-17 18:33:18 +0100
committerGuilhem Moulin <guilhem.moulin@ens-lyon.org>2012-02-17 18:33:18 +0100
commit32d8b0131bea5bb8dbd485643c9c126064055b5f (patch)
tree59d375589991c161dd53570b3bf5345cbc651f0d
parentd1e1052a437054bc6c0cab3fe8b150a9fd5a435f (diff)
removing empty dirs (fix)
-rwxr-xr-xvideomv.pl2
-rwxr-xr-xvideorm.pl14
2 files changed, 15 insertions, 1 deletions
diff --git a/videomv.pl b/videomv.pl
index d103aac..a96e62d 100755
--- a/videomv.pl
+++ b/videomv.pl
@@ -542,7 +542,7 @@ if (defined $old_symlink) {
&perform ("Deleting old symlink... ", unlink $old_symlink);
}
-open my $DIR, catdir($directors, $old_director) or die "Can't open: $!";
+opendir my $DIR, catdir($directors, $old_director) or die "Can't open: $!";
if (scalar(grep(!/^\.\.?$/, readdir $DIR) == 0)) {
&perform ("Removing empty dir... ", rmdir catdir($directors, $old_director));
}
diff --git a/videorm.pl b/videorm.pl
index c4046e4..d05da9f 100755
--- a/videorm.pl
+++ b/videorm.pl
@@ -152,6 +152,11 @@ my $file = basename ($ARGV[0]);
my $file_s = catfile ($symlinks, $file);
my $file_d;
$file_d = catfile ($symlinks, readlink $file_s) if -l $file_s;
+my $director;
+if (-l $file_s) {
+ my @director = File::Spec->splitdir(readlink $file_s);
+ $director = $director[2] if $#director >= 2;
+}
# Connect to database
@@ -184,6 +189,15 @@ my $r = 0;
&ack ( "Deleting target... ",
(defined $file_d) && -f $file_d && unlink $file_d );
+if (defined $director) {
+ opendir my $DIR, catdir($directors, $director) or die "Can't open: $!";
+ if (scalar(grep(!/^\.\.?$/, readdir $DIR) == 0)) {
+ &ack ( "Removing empty dir...",
+ rmdir catdir($directors, $director) );
+ }
+ closedir $DIR or die "Can't close: $!";
+}
+
$dbh->disconnect();
exit $r;