Created
September 29, 2010 12:52
-
-
Save anonymous/602691 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for mod in dav_fs.conf dav_fs.load dav.load dav_lock.load; do | |
(cd /etc/apache2/mods-enabled; ln -s ../mods-available/${mod}) | |
done | |
cat<<EOF>/etc/apache2/conf.d/recollection.dav | |
Alias /working/ "/software/data/factory/working/" | |
<Directory "/software/data/factory/working/"> | |
DAV On | |
PerlFixupHandler +ApachePerl::AutoMKCOL | |
PerlCleanupHandler +ApachePerl::AutoDeleteEmpty | |
Options Indexes MultiViews FollowSymLinks | |
AllowOverride None | |
Order allow,deny | |
Allow from all | |
</Directory> | |
EOF | |
mkdir /var/www/working | |
/etc/init.d/apache2 restart | |
################################################################################ | |
# /etc/apache2/ApachePerl/AutoMKCOL.pm | |
########################################################### | |
# | |
# This is a PerlFixupHandler that will take any PUT | |
# requests, determine the path required, and if it doesn't | |
# exist, creates the whole path. If there is a problem | |
# creating the path, an error is generated. | |
# | |
########################################################### | |
package ApachePerl::AutoMKCOL; | |
use strict; | |
use warnings; | |
use Apache2::RequestRec (); | |
use Apache2::ServerRec (); | |
use Apache2::Log (); | |
use File::Path; | |
use File::Basename; | |
# Compile constants | |
use Apache2::Const -compile => qw(DECLINED); | |
sub handler { | |
my $r = shift; | |
# Create directories if processing a put request. | |
if ($r->method() eq "PUT") | |
{ | |
# The full file system path to the file requested is a concat of the request filename and path_info. | |
my $fullpath = $r->filename() . $r->path_info(); | |
my $dirname = dirname($fullpath); | |
# If the directory doesn't exist, create it | |
if (!(-d $dirname)) | |
{ | |
$r->log->info("Creating directory structure for PUT request: '" . $dirname . "'."); | |
my @dirlist = mkpath ($dirname); | |
# If at least one directory wasn't created, there was a problem | |
die "Failed to create directory structure: '" . $dirname . "'." unless $#dirlist > -1; | |
} | |
} | |
# Allow next handler to run | |
return Apache2::Const::DECLINED; | |
} | |
1; | |
################################################################################ | |
#/etc/apache2/ApachePerl/AutoDeleteEmpty.pm | |
########################################################### | |
# | |
# This is a PerlCleanupHandler that will, after any DELETE | |
# requests, traverse the path for the file deleted | |
# backwards and delete any empty directories | |
# | |
########################################################### | |
package ApachePerl::AutoDeleteEmpty; | |
use strict; | |
use warnings; | |
use Apache2::RequestRec (); | |
use Apache2::ServerRec (); | |
use Apache2::Log (); | |
use File::Path; | |
use File::Basename; | |
# Compile constants | |
use Apache2::Const -compile => qw(DECLINED); | |
sub handler { | |
my $r = shift; | |
# Create directories if processing a put request. | |
if ($r->method() eq "DELETE") | |
{ | |
# The full file system path to the file requested is a concat of the request filename and path_info. | |
my $fullpath = $r->filename() . $r->path_info(); | |
my $dirname = dirname($fullpath); | |
opendir(my $dh, $dirname) || warn "can't opendir $dirname: $!"; | |
my @files = grep { /^[^\.]+/ && -f "$dirname/$_" } readdir($dh); | |
closedir($dh); | |
if($#files < 0){ rmdir $dirname || warn "cannot remove $dirname $!!"; } | |
my @dirparts=split('/',$dirname); | |
while(pop(@dirparts)){ | |
$dirname=join('/',@dirparts); | |
opendir(my $dh, $dirname) || warn "can't opendir $dirname: $!"; | |
my @files = grep { /^[^\.]+/ } readdir($dh); | |
closedir($dh); | |
if($#files < 0){ | |
rmdir $dirname || warn "cannot remove $dirname $!!"; | |
}else{ | |
# no point in continuing if this directory is not empty | |
return Apache2::Const::DECLINED; | |
} | |
} | |
} | |
# Allow next handler to run | |
return Apache2::Const::DECLINED; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment