Skip to content

Commit

Permalink
Switch to using Archive::Zip::SimpleZip
Browse files Browse the repository at this point in the history
 and improve tar ball created without chdir
  • Loading branch information
pstaabp committed Aug 20, 2023
1 parent 4c2ce01 commit 6a56ba8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bin/check_modules.pl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ =head1 DESCRIPTION
);

my @modulesList = qw(
Archive::Zip
Archive::Zip::SimpleZip
Array::Utils
Benchmark
Carp
Expand Down
1 change: 0 additions & 1 deletion conf/site.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ $webwork_server_admin_email = '';
####################################################
# system utilities
####################################################
$externalPrograms{tar} = "/bin/tar";
$externalPrograms{git} = "/usr/bin/git";

####################################################
Expand Down
9 changes: 4 additions & 5 deletions lib/HardcopyRenderedProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/WeBWorK/ContentGenerator/Hardcopy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down Expand Up @@ -739,12 +739,12 @@ 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";
}

Expand Down
14 changes: 8 additions & 6 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6a56ba8

Please sign in to comment.