Mercurial > octave
comparison scripts/pkg/private/install.m @ 28087:9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
* dirfns.cc (Frmdir): Change DEFMETHODX macro invocation to include nargout variable.
Check nargout, and for cases where "nargout == 0" and "status" indicates failure,
throw an error. For cases where "nargout > 0", return 3-value octave_value_list
in variable "retval".
* file-io.cc, gzip.cc, dir.m, isfolder.m, mkdir.m, run.m, tar.m,
unpack.m, zip.m, pathdef.m, savepath.m, configure_make.m, install.m,
uninstall.m, getpref.m, setpref.m, pkg.tst, publish.tst, system.tst:
Change calls from "rmdir" to "sts = rmdir" so that an error is not
unecessarily thrown in BIST tests and other clean up code.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 17 Feb 2020 20:02:18 -0800 |
parents | bd51beb6205e |
children | 5a07c798eb08 |
comparison
equal
deleted
inserted
replaced
28086:32af6bb2a120 | 28087:9cb04a9e81ec |
---|---|
143 endif | 143 endif |
144 endfor | 144 endfor |
145 catch | 145 catch |
146 ## Something went wrong, delete tmpdirs. | 146 ## Something went wrong, delete tmpdirs. |
147 for i = 1:length (tmpdirs) | 147 for i = 1:length (tmpdirs) |
148 rmdir (tmpdirs{i}, "s"); | 148 sts = rmdir (tmpdirs{i}, "s"); |
149 endfor | 149 endfor |
150 rethrow (lasterror ()); | 150 rethrow (lasterror ()); |
151 end_try_catch | 151 end_try_catch |
152 | 152 |
153 ## Check dependencies. | 153 ## Check dependencies. |
197 copy_built_files (desc, pdir, verbose); | 197 copy_built_files (desc, pdir, verbose); |
198 endfor | 198 endfor |
199 catch | 199 catch |
200 ## Something went wrong, delete tmpdirs. | 200 ## Something went wrong, delete tmpdirs. |
201 for i = 1:length (tmpdirs) | 201 for i = 1:length (tmpdirs) |
202 rmdir (tmpdirs{i}, "s"); | 202 sts = rmdir (tmpdirs{i}, "s"); |
203 endfor | 203 endfor |
204 rethrow (lasterror ()); | 204 rethrow (lasterror ()); |
205 end_try_catch | 205 end_try_catch |
206 | 206 |
207 ## Uninstall the packages that will be replaced. | 207 ## Uninstall the packages that will be replaced. |
216 endif | 216 endif |
217 endfor | 217 endfor |
218 catch | 218 catch |
219 ## Something went wrong, delete tmpdirs. | 219 ## Something went wrong, delete tmpdirs. |
220 for i = 1:length (tmpdirs) | 220 for i = 1:length (tmpdirs) |
221 rmdir (tmpdirs{i}, "s"); | 221 sts = rmdir (tmpdirs{i}, "s"); |
222 endfor | 222 endfor |
223 rethrow (lasterror ()); | 223 rethrow (lasterror ()); |
224 end_try_catch | 224 end_try_catch |
225 | 225 |
226 ## Install each package. | 226 ## Install each package. |
235 generate_lookfor_cache (desc); | 235 generate_lookfor_cache (desc); |
236 endfor | 236 endfor |
237 catch | 237 catch |
238 ## Something went wrong, delete tmpdirs. | 238 ## Something went wrong, delete tmpdirs. |
239 for i = 1:length (tmpdirs) | 239 for i = 1:length (tmpdirs) |
240 rmdir (tmpdirs{i}, "s"); | 240 sts = rmdir (tmpdirs{i}, "s"); |
241 endfor | 241 endfor |
242 for i = 1:length (descriptions) | 242 for i = 1:length (descriptions) |
243 rmdir (descriptions{i}.dir, "s"); | 243 sts = rmdir (descriptions{i}.dir, "s"); |
244 rmdir (getarchdir (descriptions{i}), "s"); | 244 sts = rmdir (getarchdir (descriptions{i}), "s"); |
245 endfor | 245 endfor |
246 rethrow (lasterror ()); | 246 rethrow (lasterror ()); |
247 end_try_catch | 247 end_try_catch |
248 | 248 |
249 ## Check if the installed directory is empty. If it is remove it | 249 ## Check if the installed directory is empty. If it is remove it |
250 ## from the list. | 250 ## from the list. |
251 for i = length (descriptions):-1:1 | 251 for i = length (descriptions):-1:1 |
252 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) | 252 if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) |
253 && dirempty (getarchdir (descriptions{i}))) | 253 && dirempty (getarchdir (descriptions{i}))) |
254 warning ("package %s is empty\n", descriptions{i}.name); | 254 warning ("package %s is empty\n", descriptions{i}.name); |
255 rmdir (descriptions{i}.dir, "s"); | 255 sts = rmdir (descriptions{i}.dir, "s"); |
256 rmdir (getarchdir (descriptions{i}), "s"); | 256 sts = rmdir (getarchdir (descriptions{i}), "s"); |
257 descriptions(i) = []; | 257 descriptions(i) = []; |
258 endif | 258 endif |
259 endfor | 259 endfor |
260 | 260 |
261 ## Add the packages to the package list. | 261 ## Add the packages to the package list. |
280 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; | 280 installed_pkgs_lst = {local_packages{:}, global_packages{:}}; |
281 endif | 281 endif |
282 catch | 282 catch |
283 ## Something went wrong, delete tmpdirs. | 283 ## Something went wrong, delete tmpdirs. |
284 for i = 1:length (tmpdirs) | 284 for i = 1:length (tmpdirs) |
285 rmdir (tmpdirs{i}, "s"); | 285 sts = rmdir (tmpdirs{i}, "s"); |
286 endfor | 286 endfor |
287 for i = 1:length (descriptions) | 287 for i = 1:length (descriptions) |
288 rmdir (descriptions{i}.dir, "s"); | 288 sts = rmdir (descriptions{i}.dir, "s"); |
289 endfor | 289 endfor |
290 if (global_install) | 290 if (global_install) |
291 printf ("error: couldn't append to %s\n", global_list); | 291 printf ("error: couldn't append to %s\n", global_list); |
292 else | 292 else |
293 printf ("error: couldn't append to %s\n", local_list); | 293 printf ("error: couldn't append to %s\n", local_list); |
374 ## If the directory "inst" doesn't exist, we create it. | 374 ## If the directory "inst" doesn't exist, we create it. |
375 inst_dir = fullfile (packdir, "inst"); | 375 inst_dir = fullfile (packdir, "inst"); |
376 if (! isfolder (inst_dir)) | 376 if (! isfolder (inst_dir)) |
377 [status, msg] = mkdir (inst_dir); | 377 [status, msg] = mkdir (inst_dir); |
378 if (status != 1) | 378 if (status != 1) |
379 rmdir (desc.dir, "s"); | 379 sts = rmdir (desc.dir, "s"); |
380 error ("the 'inst' directory did not exist and could not be created: %s", | 380 error ("the 'inst' directory did not exist and could not be created: %s", |
381 msg); | 381 msg); |
382 endif | 382 endif |
383 endif | 383 endif |
384 | 384 |
448 printf (" %s", archindependent{:}); | 448 printf (" %s", archindependent{:}); |
449 printf ("%s\n", instdir); | 449 printf ("%s\n", instdir); |
450 endif | 450 endif |
451 [status, output] = copyfile (archindependent, instdir); | 451 [status, output] = copyfile (archindependent, instdir); |
452 if (status != 1) | 452 if (status != 1) |
453 rmdir (desc.dir, "s"); | 453 sts = rmdir (desc.dir, "s"); |
454 error ("Couldn't copy files from 'src' to 'inst': %s", output); | 454 error ("Couldn't copy files from 'src' to 'inst': %s", output); |
455 endif | 455 endif |
456 endif | 456 endif |
457 if (! all (isspace ([archdependent{:}]))) | 457 if (! all (isspace ([archdependent{:}]))) |
458 if (verbose) | 458 if (verbose) |
463 if (! isfolder (archdir)) | 463 if (! isfolder (archdir)) |
464 mkdir (archdir); | 464 mkdir (archdir); |
465 endif | 465 endif |
466 [status, output] = copyfile (archdependent, archdir); | 466 [status, output] = copyfile (archdependent, archdir); |
467 if (status != 1) | 467 if (status != 1) |
468 rmdir (desc.dir, "s"); | 468 sts = rmdir (desc.dir, "s"); |
469 error ("Couldn't copy files from 'src' to 'inst': %s", output); | 469 error ("Couldn't copy files from 'src' to 'inst': %s", output); |
470 endif | 470 endif |
471 endif | 471 endif |
472 endif | 472 endif |
473 | 473 |
515 ## Copy the files from "inst" to installdir. | 515 ## Copy the files from "inst" to installdir. |
516 instdir = fullfile (packdir, "inst"); | 516 instdir = fullfile (packdir, "inst"); |
517 if (! dirempty (instdir)) | 517 if (! dirempty (instdir)) |
518 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); | 518 [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); |
519 if (status != 1) | 519 if (status != 1) |
520 rmdir (desc.dir, "s"); | 520 sts = rmdir (desc.dir, "s"); |
521 error ("couldn't copy files to the installation directory"); | 521 error ("couldn't copy files to the installation directory"); |
522 endif | 522 endif |
523 if (isfolder (fullfile (desc.dir, getarch ())) | 523 if (isfolder (fullfile (desc.dir, getarch ())) |
524 && ! is_same_file (fullfile (desc.dir, getarch ()), octfiledir)) | 524 && ! is_same_file (fullfile (desc.dir, getarch ()), octfiledir)) |
525 if (! isfolder (octfiledir)) | 525 if (! isfolder (octfiledir)) |
530 if (! isfolder (octm2)) | 530 if (! isfolder (octm2)) |
531 octm3 = fileparts (octm2); | 531 octm3 = fileparts (octm2); |
532 if (! isfolder (octm3)) | 532 if (! isfolder (octm3)) |
533 [status, output] = mkdir (octm3); | 533 [status, output] = mkdir (octm3); |
534 if (status != 1) | 534 if (status != 1) |
535 rmdir (desc.dir, "s"); | 535 sts = rmdir (desc.dir, "s"); |
536 error ("couldn't create installation directory %s : %s", | 536 error ("couldn't create installation directory %s : %s", |
537 octm3, output); | 537 octm3, output); |
538 endif | 538 endif |
539 endif | 539 endif |
540 [status, output] = mkdir (octm2); | 540 [status, output] = mkdir (octm2); |
541 if (status != 1) | 541 if (status != 1) |
542 rmdir (desc.dir, "s"); | 542 sts = rmdir (desc.dir, "s"); |
543 error ("couldn't create installation directory %s : %s", | 543 error ("couldn't create installation directory %s : %s", |
544 octm2, output); | 544 octm2, output); |
545 endif | 545 endif |
546 endif | 546 endif |
547 [status, output] = mkdir (octm1); | 547 [status, output] = mkdir (octm1); |
548 if (status != 1) | 548 if (status != 1) |
549 rmdir (desc.dir, "s"); | 549 sts = rmdir (desc.dir, "s"); |
550 error ("couldn't create installation directory %s : %s", | 550 error ("couldn't create installation directory %s : %s", |
551 octm1, output); | 551 octm1, output); |
552 endif | 552 endif |
553 endif | 553 endif |
554 [status, output] = mkdir (octfiledir); | 554 [status, output] = mkdir (octfiledir); |
555 if (status != 1) | 555 if (status != 1) |
556 rmdir (desc.dir, "s"); | 556 sts = rmdir (desc.dir, "s"); |
557 error ("couldn't create installation directory %s : %s", | 557 error ("couldn't create installation directory %s : %s", |
558 octfiledir, output); | 558 octfiledir, output); |
559 endif | 559 endif |
560 endif | 560 endif |
561 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), | 561 [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), |
562 octfiledir); | 562 octfiledir); |
563 rmdir (fullfile (desc.dir, getarch ()), "s"); | 563 sts = rmdir (fullfile (desc.dir, getarch ()), "s"); |
564 | 564 |
565 if (status != 1) | 565 if (status != 1) |
566 rmdir (desc.dir, "s"); | 566 sts = rmdir (desc.dir, "s"); |
567 rmdir (octfiledir, "s"); | 567 sts = rmdir (octfiledir, "s"); |
568 error ("couldn't copy files to the installation directory"); | 568 error ("couldn't copy files to the installation directory"); |
569 endif | 569 endif |
570 endif | 570 endif |
571 | 571 |
572 endif | 572 endif |
573 | 573 |
574 ## Create the "packinfo" directory. | 574 ## Create the "packinfo" directory. |
575 packinfo = fullfile (desc.dir, "packinfo"); | 575 packinfo = fullfile (desc.dir, "packinfo"); |
576 [status, msg] = mkdir (packinfo); | 576 [status, msg] = mkdir (packinfo); |
577 if (status != 1) | 577 if (status != 1) |
578 rmdir (desc.dir, "s"); | 578 sts = rmdir (desc.dir, "s"); |
579 rmdir (octfiledir, "s"); | 579 sts = rmdir (octfiledir, "s"); |
580 error ("couldn't create packinfo directory: %s", msg); | 580 error ("couldn't create packinfo directory: %s", msg); |
581 endif | 581 endif |
582 | 582 |
583 packinfo_copy_file ("DESCRIPTION", "required", packdir, packinfo, desc, octfiledir); | 583 packinfo_copy_file ("DESCRIPTION", "required", packdir, packinfo, desc, octfiledir); |
584 packinfo_copy_file ("COPYING", "required", packdir, packinfo, desc, octfiledir); | 584 packinfo_copy_file ("COPYING", "required", packdir, packinfo, desc, octfiledir); |
594 else | 594 else |
595 try | 595 try |
596 write_index (desc, fullfile (packdir, "inst"), | 596 write_index (desc, fullfile (packdir, "inst"), |
597 fullfile (packinfo, "INDEX"), global_install); | 597 fullfile (packinfo, "INDEX"), global_install); |
598 catch | 598 catch |
599 rmdir (desc.dir, "s"); | 599 sts = rmdir (desc.dir, "s"); |
600 rmdir (octfiledir, "s"); | 600 sts = rmdir (octfiledir, "s"); |
601 rethrow (lasterror ()); | 601 rethrow (lasterror ()); |
602 end_try_catch | 602 end_try_catch |
603 endif | 603 endif |
604 | 604 |
605 ## Is there an 'on_uninstall.m' to install? | 605 ## Is there an 'on_uninstall.m' to install? |
627 if (! exist (filepath, "file") && strcmpi (requirement, "optional")) | 627 if (! exist (filepath, "file") && strcmpi (requirement, "optional")) |
628 ## do nothing, it's still OK | 628 ## do nothing, it's still OK |
629 else | 629 else |
630 [status, output] = copyfile (filepath, packinfo); | 630 [status, output] = copyfile (filepath, packinfo); |
631 if (status != 1) | 631 if (status != 1) |
632 rmdir (desc.dir, "s"); | 632 sts = rmdir (desc.dir, "s"); |
633 rmdir (octfiledir, "s"); | 633 sts = rmdir (octfiledir, "s"); |
634 error ("Couldn't copy %s file: %s", filename, output); | 634 error ("Couldn't copy %s file: %s", filename, output); |
635 endif | 635 endif |
636 endif | 636 endif |
637 | 637 |
638 endfunction | 638 endfunction |
799 cd (packdir); | 799 cd (packdir); |
800 post_install (desc); | 800 post_install (desc); |
801 cd (wd); | 801 cd (wd); |
802 catch | 802 catch |
803 cd (wd); | 803 cd (wd); |
804 rmdir (desc.dir, "s"); | 804 sts = rmdir (desc.dir, "s"); |
805 rmdir (getarchdir (desc), "s"); | 805 sts = rmdir (getarchdir (desc), "s"); |
806 rethrow (lasterror ()); | 806 rethrow (lasterror ()); |
807 end_try_catch | 807 end_try_catch |
808 endif | 808 endif |
809 | 809 |
810 endfunction | 810 endfunction |