From f413c029a2557974b52ed16cf45200206e172ad6 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 19 May 2006 21:48:10 +0000 Subject: [PATCH] Storage now prunes empty directories when delete is called. Add use WebGUI::Form::Hidden to Form::File --- docs/changelog/6.x.x.txt | 3 +++ lib/WebGUI/Form/File.pm | 1 + lib/WebGUI/Storage.pm | 14 +++++++++++++- t/Storage.t | 10 +++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 860fa09cf..6e9ea2392 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -4,12 +4,15 @@ - fixed a bug in the project management app that was causing a no privilege error when trying to display the view. - fixed various bugs in the project management app. - added right click ment to project management app. + - If a storage object is deleted, it will prune the directory structure + upward if the directories are empty, until it reaches the uploads dir. - fix [ 1489017 ] Changing default time zone can disable site - fix [ 1490812 ] Events cannot be purged. - fix [ 1466902 ] $u->status('Deactivated') does not expire existing sessions - fix - msgs with only text/html not accepted as such - fix - getCsMail doesn't recognize References - Added duplicate button in asset manager as discussed in Community IRC. + - fix - WebGUI::Form::File doesn't use WebGUI::Form::Hidden 6.99.1 - Bugfixes on dashboard to fix template errors. diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index d084657dc..dc58ee28a 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -18,6 +18,7 @@ use strict; use base 'WebGUI::Form::Control'; use WebGUI::International; use WebGUI::Storage; +use WebGUI::Form::Hidden; =head1 NAME diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm index e5f095c9f..292df0141 100644 --- a/lib/WebGUI/Storage.pm +++ b/lib/WebGUI/Storage.pm @@ -376,7 +376,19 @@ Deletes this storage location and its contents (if any) from the filesystem. sub delete { my $self = shift; my $path = $self->getPath; - rmtree($path) if ($path); + if ($path) { + rmtree($path) if ($path); + foreach my $subDir ($self->{_part1}.'/'.$self->{_part2}, $self->{_part1}) { + my $uDir = $self->session->config->get('uploadsPath') . '/' . $subDir; + opendir my $DH, $uDir or + $self->session->errorHandler->fatal("Unable to open $uDir for directory reading"); + my @dirs = grep { !/^\.+$/ } readdir($DH); + if (scalar @dirs == 0) { + rmtree($uDir); + } + close $DH; + } + } return; } diff --git a/t/Storage.t b/t/Storage.t index 60efaf376..ce0815571 100644 --- a/t/Storage.t +++ b/t/Storage.t @@ -11,6 +11,7 @@ use FindBin; use strict; use lib "$FindBin::Bin/lib"; +our $todo; use WebGUI::Test; use WebGUI::Session; @@ -18,7 +19,7 @@ use WebGUI::Storage; use Test::More; -plan tests => 8; # increment this value for each test you create +plan tests => 9; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -48,6 +49,13 @@ $storage1->delete; ok( !(-e $storageDir1), "Storage location deleted"); +undef $storage1; + +TODO: { + local $TODO = "Tests to make later"; + ok(0, 'Create object with 1 character GUID'); +} + END { ref $storage1 eq "WebGUI::Storage" and $storage1->delete; }