diff --git a/bin/check_modules.pl b/bin/check_modules.pl index 3c7d3c4dc1..f9e0546737 100755 --- a/bin/check_modules.pl +++ b/bin/check_modules.pl @@ -65,7 +65,6 @@ =head1 DESCRIPTION ); my @modulesList = qw( - Archive::Zip Archive::Zip::SimpleZip Array::Utils Benchmark diff --git a/conf/site.conf.dist b/conf/site.conf.dist index 3c5fca4e45..4d281656b3 100644 --- a/conf/site.conf.dist +++ b/conf/site.conf.dist @@ -82,7 +82,6 @@ $webwork_server_admin_email = ''; #################################################### # system utilities #################################################### -$externalPrograms{tar} = "/bin/tar"; $externalPrograms{git} = "/usr/bin/git"; #################################################### diff --git a/lib/HardcopyRenderedProblem.pm b/lib/HardcopyRenderedProblem.pm index 13a6ed84a8..c13865bd13 100644 --- a/lib/HardcopyRenderedProblem.pm +++ b/lib/HardcopyRenderedProblem.pm @@ -28,7 +28,7 @@ use warnings; use File::Path; use String::ShellQuote; -use Archive::Zip qw(:ERROR_CODES); +use Archive::Zip::SimpleZip qw($SimpleZipError); use Mojo::File qw(path tempdir); use XML::LibXML; @@ -172,11 +172,10 @@ sub generate_hardcopy_tex { push(@$errors, "Failed to generate error log file: $@") if $@; # Create a zip archive of the bundle directory - my $zip = Archive::Zip->new; - $zip->addTree($working_dir->dirname->to_string); + my $zip = Archive::Zip::SimpleZip->new($working_dir->dirname->child('hardcopy.zip')->to_string); + $zip->add($working_dir->dirname->to_string, storelinks => 1); - push(@$errors, qq{Failed to create zip archive of directory "$working_dir"}) - unless ($zip->writeToFileNamed($working_dir->dirname->child('hardcopy.zip')->to_string) == AZ_OK); + push(@$errors, qq{Failed to create zip archive of directory "$working_dir": $SimpleZipError}) unless ($zip->close); return; } diff --git a/lib/WeBWorK/ContentGenerator/Hardcopy.pm b/lib/WeBWorK/ContentGenerator/Hardcopy.pm index 34b8d36b07..7750346a72 100644 --- a/lib/WeBWorK/ContentGenerator/Hardcopy.pm +++ b/lib/WeBWorK/ContentGenerator/Hardcopy.pm @@ -27,7 +27,7 @@ use File::Path; use File::Copy qw(move copy); use File::Temp qw/tempdir/; use String::ShellQuote; -use Archive::Zip qw(:ERROR_CODES); +use Archive::Zip::SimpleZip qw($SimpleZipError); use XML::LibXML; use WeBWorK::DB::Utils qw/user2global/; @@ -739,12 +739,16 @@ sub generate_hardcopy_tex ($c, $temp_dir_path, $final_file_basename) { } # Create a zip archive of the bundle directory - my $zip = Archive::Zip->new(); - $zip->addTree($temp_dir_path); + my $zip_file = "$temp_dir_path/$final_file_basename.zip"; + my $zip = Archive::Zip::SimpleZip->new($zip_file); + $zip->add($temp_dir_path, Name => "hardcopy_files", StoreLink => 1); - my $zip_file = "$final_file_basename.zip"; - unless ($zip->writeToFileNamed("$temp_dir_path/$zip_file") == AZ_OK) { - $c->add_error('Failed to create zip archive of directory "', $c->tag('code', $bundle_path), '"'); + unless ($zip->close) { + $c->add_error( + 'Failed to create zip archive of directory "', + $c->tag('code', $bundle_path), + ': $SimpleZipError"' + ); return "$bundle_path/$src_name"; } diff --git a/lib/WeBWorK/Utils/CourseManagement.pm b/lib/WeBWorK/Utils/CourseManagement.pm index a9bcf931e8..cdc66ea056 100644 --- a/lib/WeBWorK/Utils/CourseManagement.pm +++ b/lib/WeBWorK/Utils/CourseManagement.pm @@ -35,7 +35,7 @@ use File::Path qw(rmtree); use File::Copy qw(move); use File::Copy::Recursive qw(dircopy); use File::Spec; -use File::Find; +use Mojo::File; use Archive::Tar; use Archive::Extract; use WeBWorK::CourseEnvironment; @@ -759,12 +759,14 @@ sub archiveCourse { ##### step 2: tar and gzip course directory (including dumped database) ##### - # we want tar to run from the parent directory of the course directory - chdir("$course_dir/.."); - my @files; my $parent_dir = $ce->{webworkDirs}{courses}; - finddepth(sub { push(@files, $File::Find::name =~ s/$parent_dir\///r) }, $course_dir); - my $ok = Archive::Tar->create_archive($tmp_archive_path, COMPRESS_GZIP, @files); + my $files = Mojo::File->new($course_dir)->list_tree({ dir => 1, hidden => 1 })->map('to_abs'); + my $tar = Archive::Tar->new; + $tar->add_files(@$files); + for ($tar->get_files) { + $tar->rename($_->full_path, $_->full_path =~ s!^$parent_dir/!!r); + } + my $ok = $tar->write($tmp_archive_path, COMPRESS_GZIP); unless ($ok) { _archiveCourse_remove_dump_dir($ce, $dump_dir);