100 !Archiver class methodsFor:'documentation'! |
100 !Archiver class methodsFor:'documentation'! |
101 |
101 |
102 copyright |
102 copyright |
103 " |
103 " |
104 COPYRIGHT (c) 2003 by eXept Software AG |
104 COPYRIGHT (c) 2003 by eXept Software AG |
105 All Rights Reserved |
105 All Rights Reserved |
106 |
106 |
107 This software is furnished under a license and may be used |
107 This software is furnished under a license and may be used |
108 only in accordance with the terms of that license and with the |
108 only in accordance with the terms of that license and with the |
109 inclusion of the above copyright notice. This software may not |
109 inclusion of the above copyright notice. This software may not |
110 be provided or otherwise made available to, or used by, any |
110 be provided or otherwise made available to, or used by, any |
111 other person. No title to or ownership of the software is |
111 other person. No title to or ownership of the software is |
112 hereby transferred. |
112 hereby transferred. |
113 " |
113 " |
114 ! ! |
114 ! ! |
115 |
115 |
|
116 !Archiver class methodsFor:'initialization'! |
|
117 |
|
118 initialize |
|
119 MimeTypeMapping := Dictionary withKeysAndValues: |
|
120 #( |
|
121 'application/x-tar-compressed' CompressedTarArchive "abstract - special handling" |
|
122 'application/x-tar-gzip-compressed' TarGZipArchive |
|
123 'application/x-tar-bzip2-compressed' TarBZ2Archive |
|
124 'application/x-tar' TarArchive |
|
125 'application/x-gzip-compressed' GZipCompressed |
|
126 'application/x-zip-compressed' ZipArchive |
|
127 'application/x-bzip2-compressed' BZ2Compressed |
|
128 'application/x-squeak-archive' ZipArchive |
|
129 'application/java-archive' ZipArchive |
|
130 |
|
131 'application/x-ar-archive' ArArchive |
|
132 'application/x-ar-library' ArArchive |
|
133 'application/library' ArArchive |
|
134 |
|
135 "/ 'application/x-rpm' RPMArchive |
|
136 "/ 'application/x-rpm-archive' RPMArchive |
|
137 "/ 'application/x-redhat packet manager' RPMArchive |
|
138 ). |
|
139 ! ! |
|
140 |
116 !Archiver class methodsFor:'instance creation'! |
141 !Archiver class methodsFor:'instance creation'! |
117 |
|
118 classForMimeType:aMimeType |
|
119 ^ self classForMimeType:aMimeType fileName:nil |
|
120 |
|
121 " |
|
122 self classForMimeType:'application/x-tar' |
|
123 self classForMimeType:'application/x-foo' |
|
124 self classForMimeType:'application/x-squeak-archive' |
|
125 self classForMimeType:'application/java-archive' |
|
126 'foo.sar' asFilename mimeTypeFromName |
|
127 'foo.jar' asFilename mimeTypeFromName |
|
128 'foo.a' asFilename mimeTypeFromName |
|
129 " |
|
130 ! |
|
131 |
142 |
132 classForMimeType:aMimeType fileName:aFileNameOrNil |
143 classForMimeType:aMimeType fileName:aFileNameOrNil |
133 |className| |
144 |className| |
134 |
145 |
135 aMimeType isNil ifTrue:[^ nil]. |
146 className := MimeTypeMapping at:aMimeType ifAbsent:[^ nil]. |
136 |
147 |
137 className := ( |
148 className = #CompressedTarArchive ifTrue:[ |
138 #( |
149 (aFileNameOrNil notNil and:[aFileNameOrNil suffix = 'bz2']) ifTrue:[ |
139 ('application/x-tar-compressed' CompressedTarArchive ) "/ abstract - see below |
150 className := #TarBZ2Archive |
140 ('application/x-tar-gzip-compressed' TarGZipArchive ) |
151 ] ifFalse:[ |
141 ('application/x-tar-bzip2-compressed' TarBZ2Archive ) |
152 "this is the default" |
142 ('application/x-tar' TarArchive ) |
153 className := #TarGZipArchive |
143 ('application/x-gzip-compressed' GZipCompressed ) |
154 ] |
144 ('application/x-zip-compressed' ZipArchive ) |
|
145 ('application/x-bzip2-compressed' BZ2Compressed ) |
|
146 ('application/x-squeak-archive' ZipArchive ) |
|
147 ('application/java-archive' ZipArchive ) |
|
148 |
|
149 ('application/x-ar-archive' ArArchive ) |
|
150 ('application/x-ar-library' ArArchive ) |
|
151 ('application/library' ArArchive ) |
|
152 |
|
153 "/ ('application/x-rpm' RPMArchive ) |
|
154 "/ ('application/x-rpm-archive' RPMArchive ) |
|
155 "/ ('application/x-redhat packet manager' RPMArchive ) |
|
156 ) detect:[:entry | entry first = aMimeType] ifNone:#(nil nil) |
|
157 ) last. |
|
158 className isNil ifTrue:[^ nil]. |
|
159 |
|
160 className = CompressedTarArchive ifTrue:[ |
|
161 aFileNameOrNil isNil ifTrue:[ |
|
162 className := #TarGZipArchive |
|
163 ] ifFalse:[ |
|
164 aFileNameOrNil suffix = 'bz2' ifTrue:[ |
|
165 className := #TarBZ2Archive |
|
166 ] ifFalse:[ |
|
167 className := #TarGZipArchive |
|
168 ] |
|
169 ]. |
|
170 ]. |
155 ]. |
171 ^ self privateClassesAt:className. |
156 ^ self privateClassesAt:className. |
172 |
157 |
173 " |
158 " |
174 self classForMimeType:'application/x-tar' |
159 self classForMimeType:nil fileName:nil |
175 self classForMimeType:'application/x-foo' |
160 self classForMimeType:'application/x-tar-compressed' fileName:nil |
176 self classForMimeType:'application/x-squeak-archive' |
161 self classForMimeType:'application/x-tar' fileName:nil |
177 self classForMimeType:'application/java-archive' |
162 self classForMimeType:'application/x-foo' fileName:nil |
178 'foo.sar' asFilename mimeTypeFromName |
163 self classForMimeType:'application/x-squeak-archive' fileName:nil |
179 'foo.jar' asFilename mimeTypeFromName |
164 self classForMimeType:'application/java-archive' fileName:nil |
180 'foo.a' asFilename mimeTypeFromName |
165 'foo.sar' asFilename mimeTypeFromName |
|
166 'foo.jar' asFilename mimeTypeFromName |
|
167 'foo.a' asFilename mimeTypeFromName |
181 " |
168 " |
182 ! |
169 ! |
183 |
170 |
184 newFor:aFilename |
171 newFor:aFilename |
185 |fn mimeType archiverClass| |
172 |fn archiverClass| |
186 |
173 |
187 fn := aFilename asFilename. |
174 fn := aFilename asFilename. |
188 mimeType := fn mimeTypeFromName. |
175 archiverClass := self classForMimeType:fn mimeTypeFromName fileName:fn. |
189 archiverClass := self classForMimeType:mimeType fileName:fn. |
|
190 archiverClass isNil ifTrue:[^ nil]. |
176 archiverClass isNil ifTrue:[^ nil]. |
191 ^ archiverClass with:aFilename |
177 ^ archiverClass with:fn |
192 ! |
178 ! |
193 |
179 |
194 with:aFilename |
180 with:aFilename |
195 |
181 ^ self new fileName:aFilename. |
196 | instance | |
|
197 |
|
198 instance := self new. |
|
199 instance fileName:aFilename. |
|
200 ^ instance |
|
201 ! ! |
182 ! ! |
202 |
183 |
203 !Archiver class methodsFor:'classAccess'! |
184 !Archiver class methodsFor:'classAccess'! |
204 |
185 |
205 arArchive |
186 arArchive |
397 removeTemporaryDirectory |
378 removeTemporaryDirectory |
398 |
379 |
399 | tmp | |
380 | tmp | |
400 |
381 |
401 temporaryDirectory notNil ifTrue:[ |
382 temporaryDirectory notNil ifTrue:[ |
402 tmp := self temporaryDirectory. |
383 tmp := self temporaryDirectory. |
403 (FileDirectory directoryNamed:(tmp directory)) removeDirectory:tmp baseName. |
384 (FileDirectory directoryNamed:(tmp directory)) removeDirectory:tmp baseName. |
404 temporaryDirectory := nil. |
385 temporaryDirectory := nil. |
405 ]. |
386 ]. |
406 ! |
387 ! |
407 |
388 |
408 stopProcess |
389 stopProcess |
409 |
390 |
410 process notNil ifTrue:[ |
391 process notNil ifTrue:[ |
411 process terminateWithAllSubprocesses. |
392 process terminateWithAllSubprocesses. |
412 process waitUntilTerminated. |
393 process waitUntilTerminated. |
413 ]. |
394 ]. |
414 ! ! |
395 ! ! |
415 |
396 |
416 !Archiver methodsFor:'command execution'! |
397 !Archiver methodsFor:'command execution'! |
417 |
398 |
418 executeCommand:cmd directory:aDirectory |
399 executeCommand:cmd directory:aDirectory |
419 |
400 |
420 |
401 |
421 synchron isNil ifTrue:[synchron := true]. |
402 synchron isNil ifTrue:[synchron := true]. |
422 synchron ifTrue:[ |
403 synchron ifTrue:[ |
423 OperatingSystem |
404 OperatingSystem |
424 executeCommand:cmd |
405 executeCommand:cmd |
425 inputFrom:nil |
406 inputFrom:nil |
426 outputTo:outStream |
407 outputTo:outStream |
427 errorTo:errorStream |
408 errorTo:errorStream |
428 inDirectory:aDirectory |
409 inDirectory:aDirectory |
429 lineWise:true |
410 lineWise:true |
430 onError:[:status| false]. |
411 onError:[:status| false]. |
431 ] ifFalse:[ |
412 ] ifFalse:[ |
432 process := Process for:[ |
413 process := Process for:[ |
433 [ |
414 [ |
434 OperatingSystem |
415 OperatingSystem |
435 executeCommand:cmd |
416 executeCommand:cmd |
436 inputFrom:nil |
417 inputFrom:nil |
437 outputTo:outStream |
418 outputTo:outStream |
438 errorTo:errorStream |
419 errorTo:errorStream |
439 inDirectory:aDirectory |
420 inDirectory:aDirectory |
440 lineWise:true |
421 lineWise:true |
441 onError:[:status| false]. |
422 onError:[:status| false]. |
442 ] ensure:[ |
423 ] ensure:[ |
443 process := nil. |
424 process := nil. |
444 ]. |
425 ]. |
445 |
426 |
446 ] priority:(Processor systemBackgroundPriority). |
427 ] priority:(Processor systemBackgroundPriority). |
447 process name:('Archiver command: ', cmd). |
428 process name:('Archiver command: ', cmd). |
448 process resume. |
429 process resume. |
449 ] |
430 ] |
450 ! |
431 ! |
451 |
432 |
452 isValidOutputLine:line |
433 isValidOutputLine:line |
453 "return true, if line contains a valid list-files output line" |
434 "return true, if line contains a valid list-files output line" |
509 "/ copy archiv to tempDir |
490 "/ copy archiv to tempDir |
510 archivFile copyTo:archivInTemp. |
491 archivFile copyTo:archivInTemp. |
511 "/ keep a save copy |
492 "/ keep a save copy |
512 archivFile renameTo:(archivFile withSuffix:'sav'). |
493 archivFile renameTo:(archivFile withSuffix:'sav'). |
513 [ |
494 [ |
514 "/ copy files to be added to tempDir |
495 "/ copy files to be added to tempDir |
515 colOfFiles do:[:file | |
496 colOfFiles do:[:file | |
516 file recursiveCopyTo:(tempDir construct:(file asFilename baseName)) |
497 file recursiveCopyTo:(tempDir construct:(file asFilename baseName)) |
517 ]. |
498 ]. |
518 |
499 |
519 "/ addFiles to the tar archive |
500 "/ addFiles to the tar archive |
520 cmd := self getCommandToAdd:colOfFiles toArchive:archivInTemp. |
501 cmd := self getCommandToAdd:colOfFiles toArchive:archivInTemp. |
521 self executeCommand:cmd directory:tempDir. |
502 self executeCommand:cmd directory:tempDir. |
522 |
503 |
523 "/ copy tar archiv back |
504 "/ copy tar archiv back |
524 archivInTemp copyTo:archivFile. |
505 archivInTemp copyTo:archivFile. |
525 ] ensure:[ |
506 ] ensure:[ |
526 "/ cg: remove the tempFile |
507 "/ cg: remove the tempFile |
527 archivInTemp remove. |
508 archivInTemp remove. |
528 "/ cg: remove copied files |
509 "/ cg: remove copied files |
529 colOfFiles do:[:file | |
510 colOfFiles do:[:file | |
530 (tempDir construct:(file asFilename baseName)) remove. |
511 (tempDir construct:(file asFilename baseName)) remove. |
531 ]. |
512 ]. |
532 ]. |
513 ]. |
533 ! |
514 ! |
534 |
515 |
535 extractFiles:aColOfFilesOrNil to:aDirectory |
516 extractFiles:aColOfFilesOrNil to:aDirectory |
536 |execDir cmd| |
517 |execDir cmd| |
546 execDir := self fileName directory. |
527 execDir := self fileName directory. |
547 tempDir := self temporaryDirectory. |
528 tempDir := self temporaryDirectory. |
548 self extractFiles:aColOfFiles to:tempDir. |
529 self extractFiles:aColOfFiles to:tempDir. |
549 |
530 |
550 aColOfFiles do:[ : aFileString | |
531 aColOfFiles do:[ : aFileString | |
551 tempFile := self temporaryDirectory construct:aFileString. |
532 tempFile := self temporaryDirectory construct:aFileString. |
552 targetFile := aDirectory construct:(aFileString asFilename baseName). |
533 targetFile := aDirectory construct:(aFileString asFilename baseName). |
553 targetFile exists ifTrue:[ |
534 targetFile exists ifTrue:[ |
554 targetFile recursiveRemove. |
535 targetFile recursiveRemove. |
555 ]. |
536 ]. |
556 tempFile exists ifTrue:[ |
537 tempFile exists ifTrue:[ |
557 tempFile recursiveCopyTo:targetFile. |
538 tempFile recursiveCopyTo:targetFile. |
558 ]. |
539 ]. |
559 ]. |
540 ]. |
560 ! |
541 ! |
561 |
542 |
562 removeFilesFromArchive:aColOfFiles |
543 removeFilesFromArchive:aColOfFiles |
563 |
544 |
564 |cmd| |
545 |cmd| |
565 |
546 |
566 cmd := self getCommandToRemoveFiles:aColOfFiles. |
547 cmd := self getCommandToRemoveFiles:aColOfFiles. |
567 self executeCommand:cmd directory:(self fileName directory). |
548 self executeCommand:cmd directory:(self fileName directory). |
568 ! ! |
549 ! ! |
569 |
550 |
570 !Archiver::MultiFileArchive methodsFor:'command strings'! |
551 !Archiver::MultiFileArchive methodsFor:'command strings'! |
571 |
552 |
572 getCommandToAdd:colOfFiles toArchive:archivIn |
553 getCommandToAdd:colOfFiles toArchive:archivIn |
609 |
590 |
610 parseLine:line forItemClass:itemClass |
591 parseLine:line forItemClass:itemClass |
611 |words archiverColumns item index key| |
592 |words archiverColumns item index key| |
612 |
593 |
613 (firstLineRead not and:[archiver class hasTitleLine]) ifTrue:[ |
594 (firstLineRead not and:[archiver class hasTitleLine]) ifTrue:[ |
614 firstLineRead := true. |
595 firstLineRead := true. |
615 ^ nil. |
596 ^ nil. |
616 ]. |
597 ]. |
617 |
598 |
618 (archiver isValidOutputLine:line) ifFalse:[ |
599 (archiver isValidOutputLine:line) ifFalse:[ |
619 ^ nil. |
600 ^ nil. |
620 ]. |
601 ]. |
621 |
602 |
622 words := line asCollectionOfWords. |
603 words := line asCollectionOfWords. |
623 archiverColumns := archiver columns. |
604 archiverColumns := archiver columns. |
624 item := itemClass new. |
605 item := itemClass new. |
625 index := 1. |
606 index := 1. |
626 |
607 |
627 archiverColumns do:[:colDescr | |
608 archiverColumns do:[:colDescr | |
628 | itemWordCount itemStream itemFieldSelector itemWriter | |
609 | itemWordCount itemStream itemFieldSelector itemWriter | |
629 |
610 |
630 itemWordCount := colDescr second. |
611 itemWordCount := colDescr second. |
631 itemFieldSelector := colDescr first. |
612 itemFieldSelector := colDescr first. |
632 itemFieldSelector notNil ifTrue:[ |
613 itemFieldSelector notNil ifTrue:[ |
633 itemWriter := (itemFieldSelector , ':') asSymbol. |
614 itemWriter := (itemFieldSelector , ':') asSymbol. |
634 ]. |
615 ]. |
635 itemStream := WriteStream on:''. |
616 itemStream := WriteStream on:''. |
636 itemWordCount == #rest ifTrue:[ |
617 itemWordCount == #rest ifTrue:[ |
637 words from:index do:[:w| |
618 words from:index do:[:w| |
638 itemStream nextPutAll:w. |
619 itemStream nextPutAll:w. |
639 itemStream space. |
620 itemStream space. |
640 ]. |
621 ]. |
641 ] ifFalse:[ |
622 ] ifFalse:[ |
642 words from:index to:(index + itemWordCount - 1) do:[:w| |
623 words from:index to:(index + itemWordCount - 1) do:[:w| |
643 itemStream nextPutAll:w. |
624 itemStream nextPutAll:w. |
644 itemStream space. |
625 itemStream space. |
645 ]. |
626 ]. |
646 index := index + itemWordCount. |
627 index := index + itemWordCount. |
647 ]. |
628 ]. |
648 itemWriter notNil ifTrue:[ |
629 itemWriter notNil ifTrue:[ |
649 item perform:itemWriter with:(itemStream contents withoutSeparators). |
630 item perform:itemWriter with:(itemStream contents withoutSeparators). |
650 ]. |
631 ]. |
651 itemStream close. |
632 itemStream close. |
652 ]. |
633 ]. |
653 ((archiverColumns collect:[:el| el first]) includes:#permissions) ifTrue:[ |
634 ((archiverColumns collect:[:el| el first]) includes:#permissions) ifTrue:[ |
654 (item permissions startsWith:$d) ifTrue:[ |
635 (item permissions startsWith:$d) ifTrue:[ |
655 key := #directory. |
636 key := #directory. |
656 item isDirectory:true. |
637 item isDirectory:true. |
657 ] ifFalse:[ |
638 ] ifFalse:[ |
658 key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName). |
639 key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName). |
659 item isDirectory:false. |
640 item isDirectory:false. |
660 ]. |
641 ]. |
661 ] ifFalse:[ |
642 ] ifFalse:[ |
662 key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName). |
643 key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName). |
663 ]. |
644 ]. |
664 item icon:(FileBrowser iconForKeyMatching:key). |
645 item icon:(FileBrowser iconForKeyMatching:key). |
665 ^ item |
646 ^ item |
666 ! ! |
647 ! ! |
667 |
648 |
687 compressFile:aFile to:newFile |
668 compressFile:aFile to:newFile |
688 | cmd directory| |
669 | cmd directory| |
689 |
670 |
690 directory := newFile directory. |
671 directory := newFile directory. |
691 (directory exists) ifFalse:[ |
672 (directory exists) ifFalse:[ |
692 DialogBox warn:'cannot compress to non-existing directory ', directory asString. |
673 DialogBox warn:'cannot compress to non-existing directory ', directory asString. |
693 ]. |
674 ]. |
694 (directory isDirectory) ifFalse:[ |
675 (directory isDirectory) ifFalse:[ |
695 DialogBox warn:'cannot compress to non-directory ', directory asString. |
676 DialogBox warn:'cannot compress to non-directory ', directory asString. |
696 ]. |
677 ]. |
697 |
678 |
698 cmd := self getCommandToCompress:aFile asNew:newFile. |
679 cmd := self getCommandToCompress:aFile asNew:newFile. |
699 self executeCommand:cmd directory:directory. |
680 self executeCommand:cmd directory:directory. |
700 newFile exists ifTrue:[ |
681 newFile exists ifTrue:[ |
701 self fileName:newFile. |
682 self fileName:newFile. |
702 ]. |
683 ]. |
703 ! |
684 ! |
704 |
685 |
705 extractFiles:aColOfFilesOrNil to:aDirectory |
686 extractFiles:aColOfFilesOrNil to:aDirectory |
706 self uncompressTo:aDirectory |
687 self uncompressTo:aDirectory |
708 |
689 |
709 uncompressTo:aDirectory |
690 uncompressTo:aDirectory |
710 | cmd file newFile| |
691 | cmd file newFile| |
711 |
692 |
712 (aDirectory exists) ifFalse:[ |
693 (aDirectory exists) ifFalse:[ |
713 DialogBox warn:'cannot uncompress to non-existing directory ', aDirectory asString. |
694 DialogBox warn:'cannot uncompress to non-existing directory ', aDirectory asString. |
714 ^ self |
695 ^ self |
715 ]. |
696 ]. |
716 (aDirectory isDirectory) ifFalse:[ |
697 (aDirectory isDirectory) ifFalse:[ |
717 DialogBox warn:'cannot uncompress to file ', aDirectory asString. |
698 DialogBox warn:'cannot uncompress to file ', aDirectory asString. |
718 ^ self |
699 ^ self |
719 ]. |
700 ]. |
720 file := newFile := self fileName. |
701 file := newFile := self fileName. |
721 (file directory pathName = aDirectory pathName) ifFalse:[ |
702 (file directory pathName = aDirectory pathName) ifFalse:[ |
722 newFile := aDirectory construct:(file baseName). |
703 newFile := aDirectory construct:(file baseName). |
723 file copyTo:newFile. |
704 file copyTo:newFile. |
724 ]. |
705 ]. |
725 cmd := self getCommandToUncompress:newFile. |
706 cmd := self getCommandToUncompress:newFile. |
726 self executeCommand:cmd directory:aDirectory. |
707 self executeCommand:cmd directory:aDirectory. |
727 ! ! |
708 ! ! |
728 |
709 |
729 !Archiver::CompressedFile methodsFor:'columns'! |
710 !Archiver::CompressedFile methodsFor:'columns'! |
730 |
711 |
731 columns |
712 columns |
931 |
912 |
932 !Archiver::ArArchive methodsFor:'columns'! |
913 !Archiver::ArArchive methodsFor:'columns'! |
933 |
914 |
934 columns |
915 columns |
935 "/ colums id/readSelector words to read |
916 "/ colums id/readSelector words to read |
936 ^ #( |
917 ^ #( |
937 #(#permissions 1) |
918 #(#permissions 1) |
938 #(#ownerGroup 1) |
919 #(#ownerGroup 1) |
939 #(#size 1) |
920 #(#size 1) |
940 #(#monthName 1) |
921 #(#monthName 1) |
941 #(#dayString 1) |
922 #(#dayString 1) |
942 #(#timeString 1) |
923 #(#timeString 1) |
943 #(#yearString 1) |
924 #(#yearString 1) |
944 #(#fileName #rest) |
925 #(#fileName #rest) |
945 ) |
926 ) |
946 ! |
927 ! |
947 |
928 |
948 isValidOutputLine:line |
929 isValidOutputLine:line |
949 ('[-r][-w][-x]' match:(line copyTo:3)) ifTrue:[^ true]. |
930 ('[-r][-w][-x]' match:(line copyTo:3)) ifTrue:[^ true]. |
950 ^ false. |
931 ^ false. |
951 ! ! |
932 ! ! |
952 |
933 |
953 !Archiver::ArArchive methodsFor:'command strings'! |
934 !Archiver::ArArchive methodsFor:'command strings'! |
954 |
935 |
955 getCommandToExtractFiles:sel intoDirectory:dir |
936 getCommandToExtractFiles:sel intoDirectory:dir |
956 |stream| |
937 |stream| |
957 |
938 |
958 stream := WriteStream on:''. |
939 stream := WriteStream on:''. |
959 |
940 |
960 "/ 'x' arArchivUnpackOption |
941 "/ 'x' arArchivUnpackOption |
961 stream nextPutAll:('(cd %3 ; %1 x "%2" ' |
942 stream nextPutAll:('(cd %3 ; %1 x "%2" ' |
962 bindWith:self class arCommand |
943 bindWith:self class arCommand |
963 with:self fileName asString string |
944 with:self fileName asString string |
964 with:dir asString string). |
945 with:dir asString string). |
965 |
946 |
966 sel notNil ifTrue:[ |
947 sel notNil ifTrue:[ |
967 sel do:[:el | |
948 sel do:[:el | |
968 stream nextPutAll:' "'. |
949 stream nextPutAll:' "'. |
969 stream nextPutAll:(el asString). |
950 stream nextPutAll:(el asString). |
970 stream nextPutAll:'"' |
951 stream nextPutAll:'"' |
971 ]. |
952 ]. |
972 ]. |
953 ]. |
973 stream nextPutAll:')'. |
954 stream nextPutAll:')'. |
974 ^ stream contents. |
955 ^ stream contents. |
975 ! |
956 ! |
976 |
957 |
977 getCommandToListFiles:aColOfFiles |
958 getCommandToListFiles:aColOfFiles |
978 |stream| |
959 |stream| |
979 |
960 |
980 stream := WriteStream on:''. |
961 stream := WriteStream on:''. |
981 |
962 |
982 "/ 't' arArchivListContentsOption |
963 "/ 't' arArchivListContentsOption |
983 "/ 'v' arArchivVerboseOption |
964 "/ 'v' arArchivVerboseOption |
984 stream nextPutAll:('%1 tv "%2"' |
965 stream nextPutAll:('%1 tv "%2"' |
985 bindWith:self class arCommand |
966 bindWith:self class arCommand |
986 with:self fileName baseName). |
967 with:self fileName baseName). |
987 |
968 |
988 stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
969 stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
989 ^ stream contents. |
970 ^ stream contents. |
990 ! ! |
971 ! ! |
991 |
972 |
1039 |
1020 |
1040 stream := WriteStream on:''. |
1021 stream := WriteStream on:''. |
1041 |
1022 |
1042 "/ 'r' TarArchivAddOption |
1023 "/ 'r' TarArchivAddOption |
1043 "/ 'f' TarArchivFileOption |
1024 "/ 'f' TarArchivFileOption |
1044 stream nextPutAll:('%1 rf "%2"' |
1025 stream nextPutAll:('%1 rf "%2"' |
1045 bindWith:self class tarCommand |
1026 bindWith:self class tarCommand |
1046 with:archiveFile asString string). |
1027 with:archiveFile asString string). |
1047 |
1028 |
1048 stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
1029 stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
1049 ^ stream contents |
1030 ^ stream contents |
1050 ! |
1031 ! |
1051 |
1032 |
1052 getCommandToExtractFiles:sel intoDirectory:dir |
1033 getCommandToExtractFiles:sel intoDirectory:dir |
1053 |stream| |
1034 |stream| |
1054 |
1035 |
1055 stream := WriteStream on:''. |
1036 stream := WriteStream on:''. |
1056 |
1037 |
1057 "/ 'x' TarArchivUnpackOption |
1038 "/ 'x' TarArchivUnpackOption |
1058 "/ 'f' TarArchivFileOption |
1039 "/ 'f' TarArchivFileOption |
1059 "/ 'C' TarArchivUnpackInDirectoryOption |
1040 "/ 'C' TarArchivUnpackInDirectoryOption |
1060 stream nextPutAll:('%1 -xf "%2" -C %3' |
1041 stream nextPutAll:('%1 -xf "%2" -C %3' |
1061 bindWith:self class tarCommand |
1042 bindWith:self class tarCommand |
1062 with:self fileName asString string |
1043 with:self fileName asString string |
1063 with:dir asString). |
1044 with:dir asString). |
1064 |
1045 |
1065 sel notNil ifTrue:[ |
1046 sel notNil ifTrue:[ |
1066 sel do:[:el | |
1047 sel do:[:el | |
1067 stream nextPutAll:' "'. |
1048 stream nextPutAll:' "'. |
1068 stream nextPutAll:(el asString). |
1049 stream nextPutAll:(el asString). |
1069 stream nextPutAll:'"' |
1050 stream nextPutAll:'"' |
1070 ]. |
1051 ]. |
1071 ]. |
1052 ]. |
1072 ^ stream contents. |
1053 ^ stream contents. |
1073 ! |
1054 ! |
1074 |
1055 |
1075 getCommandToListFiles:aColOfFiles |
1056 getCommandToListFiles:aColOfFiles |
1076 |stream| |
1057 |stream| |
1077 |
1058 |
1078 stream := WriteStream on:''. |
1059 stream := WriteStream on:''. |
1079 |
1060 |
1080 "/ 't' TarArchivListContentsOption |
1061 "/ 't' TarArchivListContentsOption |
1081 "/ 'v' TarArchivVerboseOption |
1062 "/ 'v' TarArchivVerboseOption |
1082 "/ 'f' TarArchivFileOption |
1063 "/ 'f' TarArchivFileOption |
1083 stream nextPutAll:('%1 -tvf "%2"' |
1064 stream nextPutAll:('%1 -tvf "%2"' |
1084 bindWith:self class tarCommand |
1065 bindWith:self class tarCommand |
1085 with:self fileName baseName). |
1066 with:self fileName baseName). |
1086 |
1067 |
1087 stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
1068 stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
1088 ^ stream contents. |
1069 ^ stream contents. |
1089 ! |
1070 ! |
1090 |
1071 |
1091 getCommandToRemoveFiles:sel |
1072 getCommandToRemoveFiles:sel |
1092 |stream filename| |
1073 |stream filename| |
1093 |
1074 |
1094 filename := self fileName. |
1075 filename := self fileName. |
1095 filename exists ifFalse:[^ nil]. |
1076 filename exists ifFalse:[^ nil]. |
1096 |
1077 |
1097 stream := WriteStream on:''. |
1078 stream := WriteStream on:''. |
1098 |
1079 |
1099 "/ 'f' TarArchivFileOption |
1080 "/ 'f' TarArchivFileOption |
1100 stream nextPutAll:('%1 --delete -f "%2"' |
1081 stream nextPutAll:('%1 --delete -f "%2"' |
1101 bindWith:self class tarCommand |
1082 bindWith:self class tarCommand |
1102 with:self fileName baseName). |
1083 with:self fileName baseName). |
1103 |
1084 |
1104 stream nextPutAll:(self class stringWithQuotedFileBaseNames:sel). |
1085 stream nextPutAll:(self class stringWithQuotedFileBaseNames:sel). |
1105 ^ stream contents |
1086 ^ stream contents |
1106 ! ! |
1087 ! ! |
1107 |
1088 |
1247 stream := WriteStream on:''. |
1228 stream := WriteStream on:''. |
1248 |
1229 |
1249 "/ -o UnzipOverwriteExistingFilesOption |
1230 "/ -o UnzipOverwriteExistingFilesOption |
1250 "/ -d UnzipExtDirectoryOption |
1231 "/ -d UnzipExtDirectoryOption |
1251 |
1232 |
1252 stream nextPutAll:('%1 -o -d "%2" "%3"' |
1233 stream nextPutAll:('%1 -o -d "%2" "%3"' |
1253 bindWith:self class unzipCommand |
1234 bindWith:self class unzipCommand |
1254 with:dir asString string |
1235 with:dir asString string |
1255 with:self fileName asString). |
1236 with:self fileName asString). |
1256 |
1237 |
1257 self addDoubleQuotedFilenames:aColOfFiles toStream:stream. |
1238 self addDoubleQuotedFilenames:aColOfFiles toStream:stream. |
1258 ^ stream contents. |
1239 ^ stream contents. |
1259 ! |
1240 ! |
1260 |
1241 |
1261 getCommandToListFiles:aColOfFiles |
1242 getCommandToListFiles:aColOfFiles |
1262 |stream| |
1243 |stream| |
1263 |
1244 |
1264 stream := WriteStream on:''. |
1245 stream := WriteStream on:''. |
1265 |
1246 |
1266 "/ -Z ZipInfoOption |
1247 "/ -Z ZipInfoOption |
1267 "/ -h ZipHeaderOption |
1248 "/ -h ZipHeaderOption |
1268 "/ -t ZipTotalOption |
1249 "/ -t ZipTotalOption |
1269 stream nextPutAll:('%1 -Z -m -h "%2"' |
1250 stream nextPutAll:('%1 -Z -m -h "%2"' |
1270 bindWith:self class unzipCommand |
1251 bindWith:self class unzipCommand |
1271 with:self fileName asString string). |
1252 with:self fileName asString string). |
1272 |
1253 |
1273 aColOfFiles notNil ifTrue:[ self halt. |
1254 aColOfFiles notNil ifTrue:[ self halt. |
1274 self |
1255 self |
1275 addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName]) |
1256 addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName]) |
1276 toStream:stream. |
1257 toStream:stream. |
1277 ]. |
1258 ]. |
1278 ^ stream contents. |
1259 ^ stream contents. |
1279 ! |
1260 ! |
1280 |
1261 |
1281 getCommandToRemoveFiles:aColOfFiles |
1262 getCommandToRemoveFiles:aColOfFiles |
1282 |stream| |
1263 |stream| |
1283 |
1264 |
1284 stream := WriteStream on:''. |
1265 stream := WriteStream on:''. |
1285 |
1266 |
1286 stream nextPutAll:('%1 -d "%2"' |
1267 stream nextPutAll:('%1 -d "%2"' |
1287 bindWith:self class zipCommand |
1268 bindWith:self class zipCommand |
1288 with:self fileName asString string). |
1269 with:self fileName asString string). |
1289 |
1270 |
1290 self addDoubleQuotedFilenames:aColOfFiles toStream:stream. |
1271 self addDoubleQuotedFilenames:aColOfFiles toStream:stream. |
1291 ^ stream contents. |
1272 ^ stream contents. |
1292 ! ! |
1273 ! ! |
1293 |
1274 |
1294 !Archiver class methodsFor:'documentation'! |
1275 !Archiver class methodsFor:'documentation'! |
1295 |
1276 |
1296 version |
1277 version |
1297 ^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.26 2006-02-01 11:05:09 stefan Exp $' |
1278 ^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.27 2006-02-01 12:27:39 stefan Exp $' |
1298 ! ! |
1279 ! ! |
|
1280 |
|
1281 Archiver initialize! |