* Consolidate upload.pl into create-dist.pl.

svn path=/nixpkgs/trunk/; revision=622
gstqt5
Eelco Dolstra 2004-01-07 16:08:31 +00:00
parent f8554f0b81
commit 8984ebdeb8
3 changed files with 25 additions and 50 deletions

View File

@ -4,7 +4,7 @@ use strict;
# Global settings.
my $releasesDir = "/home/eelco/public_html/test";
my $releasesDir = "/home/eelco/public_html/nix";
umask 0002;
@ -16,6 +16,16 @@ sub printResult {
}
sub uploadFileTo {
my $path = shift;
open OUT, ">$path" or die "cannot create $path: $!";
while (<STDIN>) {
print OUT "$_" or die;
}
close OUT or die;
}
my $args = $ENV{"PATH_INFO"};
# Parse command.
@ -48,11 +58,7 @@ elsif ($command eq "upload") {
my $fullPath = "$releasesDir/$sessionName/$path";
open OUT, ">$fullPath" or die "cannot create $fullPath: $!";
while (<STDIN>) {
print OUT "$_" or die;
}
close OUT or die;
uploadFileTo $fullPath;
printResult "ok";
}
@ -110,6 +116,19 @@ elsif ($command eq "exists") {
}
}
# Upload a single file, outside of a release.
elsif ($command eq "put") {
$args = "/" . $args;
die unless $args =~ /^((\/[A-Za-z0-9-][A-Za-z0-9-\.]*)+)$/;
my $path = $1;
my $fullPath = "$releasesDir/$path";
uploadFileTo $fullPath;
printResult "ok";
}
else {
die "invalid command";
}

View File

@ -1,21 +0,0 @@
#! /usr/bin/perl -w
use strict;
use FileHandle;
use File::Spec;
use Digest::MD5;
my $path = $ENV{"PATH_INFO"};
# Sanitise path.
die unless $path =~ /^(\/[A-Za-z0-9-][A-Za-z0-9-\.]+)+$/;
my $fullpath = "/home/eelco/public_html/nix/$path";
open FILE, "< $fullpath" or die "cannot open $fullpath";
# !!! error checking
my $hash = Digest::MD5->new->addfile(*FILE)->hexdigest;
close FILE;
print "Content-Type: text/plain\n\n";
print "$hash";

View File

@ -1,23 +0,0 @@
#! /usr/bin/perl -w
use strict;
my $uploadpath = $ENV{"PATH_INFO"};
# Sanitise upload path.
die unless $uploadpath =~ /^(\/[A-Za-z0-9-][A-Za-z0-9-\.]*)+$/;
my $dst = "/home/eelco/public_html/nix/$uploadpath";
my $tmp = "${dst}_$$";
open OUT, ">$tmp" or die;
while (<STDIN>) {
print OUT "$_" or die;
}
close OUT or die;
rename $tmp, $dst or die;
print "Content-Type: text/plain\n\n";
print "upload succesful\n";
print "upload path: $uploadpath\n";