Description: Patch upload-prep to work on Debian
  upload-prep comes with a lot of hard-coded paths and does things
  as root. pull-and-process-data can run as Debian-dsc-statistics,
  so we need to chown some files so that they can be deleted by
  that user. This should not hurt for the traditional mechanisms that
  are running as root anyway.
Author: Marc Haber <mh+debian-packages@zugschlus.de>
Forwarded: no

--- a/collector/cron/upload-prep.pl
+++ b/collector/cron/upload-prep.pl
@@ -19,8 +19,9 @@
 #
 sleep 3;
 
+my ($uid,$gid)=(getpwnam("Debian-dsc-statistics"))[2,3];
 
-foreach my $conf (</usr/local/dsc/etc/*.conf>) {
+foreach my $conf (</var/run/dsc-statistics-collector/*.cfg>) {
 	next unless open (CONF, $conf);
 	my $rundir = undef;
 	while (<CONF>) {
@@ -44,15 +45,24 @@
 			unless (-d "$upload/$yymmdd") {
                 		mkdir "$upload/$yymmdd"
 					or die "mkdir $upload/$yymmdd: $!";
+			        chown "$uid", "$gid", "$upload/$yymmdd";
         		}
         		my $new = "$upload/$yymmdd/$old";
         		link ($old, $new) or die "ln $old $new: $!";
+		        chown "$uid", "$gid", "$new";
 			#
 			# the above link(2) could fail if the file was
 			# previously linked but not yet unlinked.  To
 			# workaround we could do some stat(2)s and
 			# ignore if they have the same inum?
 			#
+			# kill all empty subdirs
+			foreach my $dir (<upload/*/*>) {
+				if( -d "$dir" ) {
+					# this fails on a non-empty dir
+					rmdir "$dir";
+				}
+			}
 		}
 
 		unlink $old or die "unlink $old: $!";
