# HG changeset patch # User Rik # Date 1426021146 25200 # Node ID ee7159d9a330403669fa4fb94cc984eef97d5c18 # Parent 277b12eed117c042686c0b8c9f75945fa386035b tar.m: Re-code BIST test restore working directory even when test fails (bug #44007). * tar.m: Place 'chdir (orig_dir)' as first statement in unwind_protect_cleanup. Check whether files/dirs exist before attempting to delete them in unwind_protect_cleanup. diff -r 277b12eed117 -r ee7159d9a330 scripts/miscellaneous/tar.m --- a/scripts/miscellaneous/tar.m Tue Mar 10 10:28:05 2015 -0700 +++ b/scripts/miscellaneous/tar.m Tue Mar 10 13:59:06 2015 -0700 @@ -76,16 +76,17 @@ %!xtest -%! ## test gzip together with gunzip +%! ## test tar together with untar %! orig_dir = pwd (); %! unwind_protect -%! dirname = tempname; +%! dirname = tarname = outdir = ""; +%! dirname = tempname (); %! assert (mkdir (dirname)); %! chdir (dirname); %! dirname2 = "dir2"; %! assert (mkdir (dirname2)); -%! fname1 = "f1"; -%! fname2 = fullfile (dirname2, "f2"); +%! fname1 = "file1"; +%! fname2 = fullfile (dirname2, "file2"); %! fid = fopen (fname1, "wt"); %! assert (fid >= 0); %! fdisp (fid, "Hello World"); @@ -94,7 +95,7 @@ %! assert (fid >= 0); %! fdisp (fid, "Goodbye World"); %! fclose (fid); -%! tarname = [tempname ".tar"]; +%! tarname = [tempname() ".tar"]; %! filelist = tar (tarname, {dirname2, fname1}); %! if (! strcmp (filelist{3}, fname1)) %! error ("tar file contents does not match expected file"); @@ -115,11 +116,17 @@ %! fclose (fid); %! assert (str, "Goodbye World"); %! unwind_protect_cleanup -%! delete (tarname); +%! chdir (orig_dir); +%! if (exist (tarname)) +%! delete (tarname); +%! endif %! confirm_recursive_rmdir (false, "local"); -%! rmdir (dirname, "s"); -%! rmdir (outdir, "s"); -%! chdir (orig_dir); +%! if (exist (dirname)) +%! rmdir (dirname, "s"); +%! endif +%! if (exist (outdir)) +%! rmdir (outdir, "s"); +%! endif %! end_unwind_protect ## Test input validation