author | Claus Gittinger <cg@exept.de> |
Tue, 21 Oct 2003 09:21:31 +0200 | |
changeset 1334 | d5a43c7a11a6 |
parent 1255 | 32e0aa97ae82 |
child 1383 | 527dcd29a97b |
permissions | -rw-r--r-- |
1085 | 1 |
"{ Package: 'stx:libbasic2' }" |
2 |
||
3 |
Object subclass:#Archiver |
|
1089 | 4 |
instanceVariableNames:'process temporaryDirectory fileName outStream errorStream |
5 |
synchron' |
|
6 |
classVariableNames:'' |
|
7 |
poolDictionaries:'' |
|
8 |
category:'System-Support-FileFormats' |
|
1085 | 9 |
! |
10 |
||
1246 | 11 |
Object subclass:#ArchiverOutputParser |
12 |
instanceVariableNames:'firstLineRead archiver' |
|
13 |
classVariableNames:'' |
|
14 |
poolDictionaries:'' |
|
15 |
privateIn:Archiver |
|
16 |
! |
|
17 |
||
1085 | 18 |
Archiver subclass:#GZipArchive |
1089 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
privateIn:Archiver |
|
1085 | 23 |
! |
24 |
||
1215 | 25 |
Archiver subclass:#MultiFileArchive |
26 |
instanceVariableNames:'' |
|
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:Archiver |
|
30 |
! |
|
31 |
||
32 |
Archiver::MultiFileArchive subclass:#TarArchive |
|
1089 | 33 |
instanceVariableNames:'' |
34 |
classVariableNames:'' |
|
35 |
poolDictionaries:'' |
|
36 |
privateIn:Archiver |
|
1085 | 37 |
! |
38 |
||
39 |
Archiver subclass:#TarGZipArchive |
|
1089 | 40 |
instanceVariableNames:'tarArchiver tarFile' |
41 |
classVariableNames:'' |
|
42 |
poolDictionaries:'' |
|
43 |
privateIn:Archiver |
|
1085 | 44 |
! |
45 |
||
1215 | 46 |
Archiver::MultiFileArchive subclass:#ZipArchive |
1089 | 47 |
instanceVariableNames:'' |
48 |
classVariableNames:'' |
|
49 |
poolDictionaries:'' |
|
50 |
privateIn:Archiver |
|
1086 | 51 |
! |
52 |
||
1085 | 53 |
|
54 |
!Archiver class methodsFor:'instance creation'! |
|
55 |
||
1215 | 56 |
classForMimeType:aMimeType |
57 |
|className| |
|
58 |
||
59 |
aMimeType isNil ifTrue:[^ nil]. |
|
60 |
||
61 |
className := ( |
|
62 |
#( |
|
63 |
('application/x-tar-compressed' TarGZipArchive ) |
|
64 |
('application/x-tar' TarArchive ) |
|
65 |
('application/x-gzip-compressed' GZipArchive ) |
|
66 |
('application/x-zip-compressed' ZipArchive ) |
|
67 |
('application/x-squeak-archive' ZipArchive ) |
|
68 |
('application/java-archive' ZipArchive ) |
|
69 |
) detect:[:entry | entry first = aMimeType] ifNone:#(nil nil) |
|
70 |
) last. |
|
71 |
className isNil ifTrue:[^ nil]. |
|
72 |
^ self privateClassesAt:className. |
|
73 |
||
74 |
" |
|
75 |
self classForMimeType:'application/x-tar' |
|
76 |
self classForMimeType:'application/x-foo' |
|
77 |
self classForMimeType:'application/x-squeak-archive' |
|
78 |
self classForMimeType:'application/java-archive' |
|
79 |
'foo.sar' asFilename mimeTypeFromName |
|
1334 | 80 |
'foo.jar' asFilename mimeTypeFromName |
1215 | 81 |
" |
82 |
! |
|
83 |
||
84 |
newFor:aFilename |
|
85 |
|mimeType archiverClass| |
|
86 |
||
87 |
mimeType := aFilename asFilename mimeTypeFromName. |
|
88 |
archiverClass := self classForMimeType:mimeType. |
|
89 |
archiverClass isNil ifTrue:[^ nil]. |
|
90 |
^ archiverClass with:aFilename |
|
91 |
! |
|
92 |
||
1085 | 93 |
with:aFilename |
94 |
||
95 |
| instance | |
|
96 |
||
97 |
instance := self new. |
|
98 |
instance fileName:aFilename. |
|
99 |
^ instance |
|
100 |
! ! |
|
101 |
||
102 |
!Archiver class methodsFor:'classAccess'! |
|
103 |
||
104 |
gzipArchive |
|
105 |
||
106 |
^ GZipArchive |
|
107 |
! |
|
108 |
||
109 |
tarArchive |
|
110 |
||
111 |
^ TarArchive |
|
112 |
! |
|
113 |
||
114 |
tarGZipArchive |
|
115 |
||
116 |
^ TarGZipArchive |
|
1086 | 117 |
! |
118 |
||
119 |
zipArchive |
|
120 |
||
121 |
^ ZipArchive |
|
1085 | 122 |
! ! |
123 |
||
1246 | 124 |
!Archiver class methodsFor:'columns'! |
125 |
||
126 |
columns |
|
127 |
self subclassResponsibility |
|
128 |
! ! |
|
129 |
||
1255 | 130 |
!Archiver class methodsFor:'command strings'! |
131 |
||
132 |
stringWithQuotedFileBaseNames:aColOfFiles |
|
133 |
||
134 |
aColOfFiles isNil ifTrue:[^ '']. |
|
135 |
||
136 |
^ String |
|
137 |
streamContents:[:str | |
|
138 |
aColOfFiles do:[:fn | |
|
139 |
str nextPutAll:' "'. |
|
140 |
str nextPutAll:(fn asFilename baseName). |
|
141 |
str nextPutAll:'"'. |
|
142 |
]. |
|
143 |
] |
|
144 |
! ! |
|
145 |
||
1246 | 146 |
!Archiver class methodsFor:'commandOutputReader'! |
147 |
||
148 |
commandOutputParser |
|
149 |
^ self commandOutputParserClass new |
|
150 |
! |
|
151 |
||
152 |
commandOutputParserClass |
|
153 |
^ ArchiverOutputParser |
|
154 |
! ! |
|
155 |
||
1086 | 156 |
!Archiver class methodsFor:'queries'! |
157 |
||
158 |
canAddFiles |
|
159 |
||
160 |
^ false |
|
161 |
! |
|
162 |
||
1106 | 163 |
canDragnDrop |
164 |
||
165 |
^ true. |
|
166 |
! |
|
167 |
||
1098 | 168 |
canExtractFiles |
169 |
||
170 |
^ false |
|
171 |
! |
|
172 |
||
1086 | 173 |
canRemoveFiles |
174 |
||
175 |
^ false |
|
176 |
! |
|
177 |
||
1106 | 178 |
canViewFile |
179 |
||
180 |
^ false |
|
181 |
! |
|
182 |
||
1086 | 183 |
hasTitleLine |
184 |
||
185 |
^ false |
|
186 |
! ! |
|
187 |
||
1085 | 188 |
!Archiver methodsFor:'accessing'! |
189 |
||
190 |
errorStream |
|
191 |
"return the value of the instance variable 'errorStream' (automatically generated)" |
|
192 |
||
193 |
^ errorStream |
|
194 |
! |
|
195 |
||
196 |
errorStream:something |
|
197 |
"set the value of the instance variable 'errorStream' (automatically generated)" |
|
198 |
||
199 |
errorStream := something. |
|
200 |
! |
|
201 |
||
202 |
fileName |
|
203 |
"return the value of the instance variable 'fileName' (automatically generated)" |
|
204 |
||
205 |
^ fileName |
|
206 |
! |
|
207 |
||
208 |
fileName:something |
|
209 |
"set the value of the instance variable 'fileName' (automatically generated)" |
|
210 |
||
211 |
fileName := something. |
|
212 |
! |
|
213 |
||
214 |
outStream |
|
215 |
"return the value of the instance variable 'outStream' (automatically generated)" |
|
216 |
||
217 |
^ outStream |
|
218 |
! |
|
219 |
||
220 |
outStream:something |
|
221 |
"set the value of the instance variable 'outStream' (automatically generated)" |
|
222 |
||
223 |
outStream := something. |
|
224 |
! |
|
225 |
||
226 |
process |
|
227 |
"return the value of the instance variable 'process' (automatically generated)" |
|
228 |
||
229 |
^ process |
|
230 |
! |
|
231 |
||
232 |
process:something |
|
233 |
"set the value of the instance variable 'process' (automatically generated)" |
|
234 |
||
235 |
process := something. |
|
236 |
! |
|
237 |
||
238 |
synchron |
|
239 |
"return the value of the instance variable 'synchron' (automatically generated)" |
|
240 |
||
241 |
^ synchron |
|
242 |
! |
|
243 |
||
244 |
synchron:something |
|
245 |
"set the value of the instance variable 'synchron' (automatically generated)" |
|
246 |
||
247 |
synchron := something. |
|
248 |
! |
|
249 |
||
250 |
temporaryDirectory |
|
251 |
"return the value of the instance variable 'temporaryDirectory' (automatically generated)" |
|
252 |
||
253 |
temporaryDirectory isNil ifTrue:[ |
|
254 |
temporaryDirectory := Filename newTemporary. |
|
255 |
temporaryDirectory makeDirectory. |
|
256 |
]. |
|
257 |
^ temporaryDirectory |
|
258 |
! ! |
|
259 |
||
260 |
!Archiver methodsFor:'actions'! |
|
261 |
||
1215 | 262 |
extractFilesTo:aDirectory |
263 |
self extractFiles:nil to:aDirectory |
|
1085 | 264 |
! |
265 |
||
1255 | 266 |
listFiles:aColOfFiles |
267 |
|cmd dir| |
|
268 |
||
269 |
self fileName isNil ifTrue:[ ^ self]. |
|
270 |
dir := self fileName directory. |
|
271 |
cmd := self getCommandToListFiles:aColOfFiles. |
|
272 |
self executeCommand:cmd directory:dir |
|
273 |
! |
|
274 |
||
1215 | 275 |
removeFilesFromArchive:aColOfFiles |
1085 | 276 |
|
277 |
self subclassResponsibility. |
|
278 |
! ! |
|
279 |
||
1215 | 280 |
!Archiver methodsFor:'actions-basic'! |
281 |
||
282 |
addFilesToArchive:colOfFiles |
|
283 |
self subclassResponsibility. |
|
284 |
! |
|
285 |
||
286 |
extractFiles:aColOfFilesOrNil to:aDirectory |
|
287 |
self subclassResponsibility. |
|
288 |
! ! |
|
289 |
||
290 |
!Archiver methodsFor:'actions-private'! |
|
1085 | 291 |
|
292 |
removeTemporaryDirectory |
|
293 |
||
294 |
| tmp | |
|
295 |
||
296 |
temporaryDirectory notNil ifTrue:[ |
|
297 |
tmp := self temporaryDirectory. |
|
298 |
(FileDirectory directoryNamed:(tmp directory)) removeDirectory:tmp baseName. |
|
299 |
temporaryDirectory := nil. |
|
300 |
]. |
|
301 |
! |
|
302 |
||
303 |
stopProcess |
|
304 |
||
305 |
process notNil ifTrue:[ |
|
306 |
process terminateWithAllSubprocesses. |
|
307 |
process waitUntilTerminated. |
|
308 |
]. |
|
309 |
! ! |
|
310 |
||
311 |
!Archiver methodsFor:'command execution'! |
|
312 |
||
313 |
executeCommand:cmd directory:aDirectory |
|
314 |
||
315 |
||
316 |
synchron isNil ifTrue:[synchron := true]. |
|
317 |
synchron ifTrue:[ |
|
318 |
OperatingSystem |
|
319 |
executeCommand:cmd |
|
320 |
inputFrom:nil |
|
321 |
outputTo:outStream |
|
322 |
errorTo:errorStream |
|
323 |
inDirectory:aDirectory |
|
324 |
lineWise:true |
|
325 |
onError:[:status| false]. |
|
326 |
] ifFalse:[ |
|
327 |
process := Process for:[ |
|
328 |
[ |
|
329 |
OperatingSystem |
|
330 |
executeCommand:cmd |
|
331 |
inputFrom:nil |
|
332 |
outputTo:outStream |
|
333 |
errorTo:errorStream |
|
334 |
inDirectory:aDirectory |
|
335 |
lineWise:true |
|
336 |
onError:[:status| false]. |
|
1215 | 337 |
] ensure:[ |
1085 | 338 |
process := nil. |
339 |
]. |
|
340 |
||
341 |
] priority:(Processor systemBackgroundPriority). |
|
1215 | 342 |
process name:('Archiver command: ', cmd). |
1085 | 343 |
process resume. |
344 |
] |
|
345 |
! |
|
346 |
||
1246 | 347 |
isValidOutputLine:line |
348 |
"return true, if line contains a valid list-files output line" |
|
349 |
||
350 |
self subclassResponsibility |
|
351 |
! |
|
352 |
||
353 |
listFilesReader |
|
354 |
|reader| |
|
355 |
||
356 |
reader := ArchiverOutputParser new. |
|
357 |
reader archiver:self. |
|
358 |
^ reader |
|
359 |
! |
|
360 |
||
1085 | 361 |
outStream:aOutStream errorStream:aErrorStream |
362 |
||
363 |
outStream := aOutStream. |
|
364 |
errorStream := aErrorStream. |
|
365 |
! |
|
366 |
||
367 |
outStream:aOutStream errorStream:aErrorStream synchron:aBoolean |
|
368 |
||
369 |
outStream := aOutStream. |
|
370 |
errorStream := aErrorStream. |
|
371 |
synchron := aBoolean |
|
372 |
! ! |
|
373 |
||
1255 | 374 |
!Archiver methodsFor:'command strings'! |
375 |
||
376 |
addDoubleQuotedFilenames:collectionOfFilenames toStream:aStream |
|
377 |
collectionOfFilenames notNil ifTrue:[ |
|
378 |
collectionOfFilenames do:[:el | |
|
379 |
aStream nextPutAll:' "'. |
|
380 |
aStream nextPutAll:(el asString). |
|
381 |
aStream nextPutAll:'"' |
|
382 |
]. |
|
383 |
]. |
|
384 |
! ! |
|
385 |
||
1085 | 386 |
!Archiver methodsFor:'initialization & release'! |
387 |
||
388 |
release |
|
389 |
||
390 |
self stopProcess. |
|
391 |
self removeTemporaryDirectory. |
|
392 |
! ! |
|
393 |
||
1246 | 394 |
!Archiver::ArchiverOutputParser class methodsFor:'instance creation'! |
395 |
||
396 |
new |
|
397 |
^ self basicNew initialize. |
|
398 |
! ! |
|
399 |
||
400 |
!Archiver::ArchiverOutputParser methodsFor:'accessing'! |
|
401 |
||
402 |
archiver:something |
|
403 |
"set the value of the instance variable 'archiver' (automatically generated)" |
|
404 |
||
405 |
archiver := something. |
|
406 |
! ! |
|
407 |
||
408 |
!Archiver::ArchiverOutputParser methodsFor:'initialization'! |
|
1086 | 409 |
|
1246 | 410 |
initialize |
411 |
firstLineRead := false. |
|
412 |
! ! |
|
413 |
||
414 |
!Archiver::ArchiverOutputParser methodsFor:'parsing'! |
|
415 |
||
416 |
parseLine:line forItemClass:itemClass |
|
417 |
|words archiverColumns item index key| |
|
418 |
||
419 |
(firstLineRead not and:[archiver class hasTitleLine]) ifTrue:[ |
|
420 |
firstLineRead := true. |
|
421 |
^ nil. |
|
422 |
]. |
|
423 |
||
424 |
(archiver isValidOutputLine:line) ifFalse:[ |
|
425 |
^ nil. |
|
426 |
]. |
|
427 |
||
428 |
words := line asCollectionOfWords. |
|
429 |
archiverColumns := archiver columns. |
|
430 |
item := itemClass new. |
|
431 |
index := 1. |
|
1086 | 432 |
|
1246 | 433 |
archiverColumns do:[:colDescr | |
434 |
| itemWordCount itemStream itemFieldSelector itemWriter | |
|
435 |
||
436 |
itemWordCount := colDescr second. |
|
437 |
itemFieldSelector := colDescr first. |
|
438 |
itemFieldSelector notNil ifTrue:[ |
|
439 |
itemWriter := (itemFieldSelector , ':') asSymbol. |
|
440 |
]. |
|
441 |
itemStream := WriteStream on:''. |
|
442 |
itemWordCount == #rest ifTrue:[ |
|
443 |
index to:(words size) do:[:i| |
|
444 |
itemStream nextPutAll:(words at:i). |
|
445 |
itemStream space. |
|
446 |
]. |
|
447 |
] ifFalse:[ |
|
448 |
index to:(index + itemWordCount - 1) do:[:i| |
|
449 |
itemStream nextPutAll:(words at:i). |
|
450 |
itemStream space. |
|
451 |
]. |
|
452 |
index := index + itemWordCount. |
|
453 |
]. |
|
454 |
itemWriter notNil ifTrue:[ |
|
1255 | 455 |
item perform:itemWriter with:(itemStream contents withoutSeparators). |
1246 | 456 |
]. |
457 |
itemStream close. |
|
458 |
]. |
|
459 |
((archiverColumns collect:[:el| el first]) includes:#permissions) ifTrue:[ |
|
460 |
(item permissions startsWith:$d) ifTrue:[ |
|
461 |
key := #directory. |
|
462 |
item isDirectory:true. |
|
463 |
] ifFalse:[ |
|
464 |
key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName). |
|
465 |
item isDirectory:false. |
|
466 |
]. |
|
467 |
] ifFalse:[ |
|
468 |
key := MIMETypes mimeTypeForFilename:(item fileName asFilename baseName). |
|
469 |
]. |
|
470 |
item icon:(FileBrowser iconForKeyMatching:key). |
|
471 |
^ item |
|
1086 | 472 |
! ! |
473 |
||
1215 | 474 |
!Archiver::GZipArchive class methodsFor:'command strings'! |
475 |
||
476 |
gunzipCommand |
|
477 |
^ 'gunzip' |
|
478 |
! |
|
479 |
||
480 |
gzipCommand |
|
481 |
^ 'gzip' |
|
482 |
! ! |
|
483 |
||
1086 | 484 |
!Archiver::GZipArchive class methodsFor:'queries'! |
485 |
||
1106 | 486 |
canViewFile |
487 |
||
488 |
^ true |
|
489 |
! |
|
490 |
||
1086 | 491 |
hasTitleLine |
492 |
||
493 |
^ true |
|
494 |
! ! |
|
495 |
||
1085 | 496 |
!Archiver::GZipArchive methodsFor:'actions'! |
497 |
||
1215 | 498 |
extractFiles:aColOfFilesOrNil to:aDirectory |
1106 | 499 |
self unzipTo:aDirectory |
500 |
! |
|
501 |
||
1085 | 502 |
unzipTo:aDirectory |
503 |
| cmd file newFile| |
|
504 |
||
505 |
(aDirectory exists not) ifTrue:[ |
|
506 |
DialogBox warn:'cant unzip to not existing directory ', aDirectory asString. |
|
1255 | 507 |
^ self |
1085 | 508 |
]. |
509 |
(aDirectory isDirectory not) ifTrue:[ |
|
510 |
DialogBox warn:'cant unzip to file ', aDirectory asString. |
|
1255 | 511 |
^ self |
1085 | 512 |
]. |
1215 | 513 |
file := newFile := self fileName. |
514 |
(file directory pathName = aDirectory pathName) ifFalse:[ |
|
515 |
newFile := aDirectory construct:(file baseName). |
|
516 |
file copyTo:newFile. |
|
1085 | 517 |
]. |
1215 | 518 |
cmd := self getCommandToGunzip:newFile. |
1085 | 519 |
self executeCommand:cmd directory:aDirectory. |
520 |
! |
|
521 |
||
522 |
zipFile:aFile to:newFile |
|
523 |
| cmd directory| |
|
524 |
||
525 |
directory := newFile directory. |
|
1215 | 526 |
(directory exists) ifFalse:[ |
527 |
DialogBox warn:'cannot gzip to non-existing directory ', directory asString. |
|
1085 | 528 |
]. |
1215 | 529 |
(directory isDirectory) ifFalse:[ |
530 |
DialogBox warn:'cannot gzip to non-directory ', directory asString. |
|
1085 | 531 |
]. |
1215 | 532 |
|
533 |
cmd := self getCommandToGZip:aFile asNew:newFile. |
|
1085 | 534 |
self executeCommand:cmd directory:directory. |
535 |
newFile exists ifTrue:[ |
|
536 |
self fileName:newFile. |
|
537 |
]. |
|
538 |
! ! |
|
539 |
||
1246 | 540 |
!Archiver::GZipArchive methodsFor:'columns'! |
541 |
||
542 |
columns |
|
543 |
||
544 |
"/ columns in stream order |
|
1247 | 545 |
"/ colums id/readSelector words to read |
1255 | 546 |
^ #( "/ #(#method 1) |
547 |
"/ #(#crc 1) |
|
548 |
"/ #(#dateAndTime 3) |
|
1246 | 549 |
#(#compressSize 1) |
550 |
#(#size 1) |
|
551 |
#(#ratio 1) |
|
552 |
#(#fileName #rest) |
|
553 |
) |
|
1255 | 554 |
! |
555 |
||
556 |
isValidOutputLine:line |
|
557 |
^ line endsWith:self fileName withoutSuffix baseName. |
|
1246 | 558 |
! ! |
559 |
||
1085 | 560 |
!Archiver::GZipArchive methodsFor:'command strings'! |
561 |
||
1215 | 562 |
getCommandToGZip:aFile asNew:newFile |
563 |
^ '%1 -c %2 > %3' |
|
564 |
bindWith:self class gzipCommand |
|
565 |
with:aFile asString |
|
566 |
with:newFile asString |
|
1086 | 567 |
! |
568 |
||
1215 | 569 |
getCommandToGunzip:aFileName |
570 |
^ '%1 %2' |
|
571 |
bindWith:self class gunzipCommand |
|
572 |
with:aFileName baseName |
|
1255 | 573 |
! |
574 |
||
575 |
getCommandToListFiles:dummyArg |
|
576 |
^ 'gzip -l "' , self fileName baseName , '"' |
|
1215 | 577 |
! ! |
578 |
||
579 |
!Archiver::MultiFileArchive methodsFor:'actions'! |
|
580 |
||
581 |
addFilesToArchive:colOfFiles |
|
582 |
|cmd tempDir archivFile archivInTemp| |
|
583 |
||
584 |
archivFile := self fileName. |
|
585 |
||
586 |
tempDir := self temporaryDirectory. |
|
587 |
archivInTemp := tempDir construct:(archivFile baseName). |
|
588 |
||
589 |
"/ copy archiv to tempDir |
|
590 |
archivFile copyTo:archivInTemp. |
|
1246 | 591 |
"/ keep a save copy |
592 |
archivFile renameTo:(archivFile withSuffix:'sav'). |
|
593 |
[ |
|
594 |
"/ copy files to be added to tempDir |
|
595 |
colOfFiles do:[:file | |
|
596 |
file recursiveCopyTo:(tempDir construct:(file asFilename baseName)) |
|
597 |
]. |
|
1215 | 598 |
|
1246 | 599 |
"/ addFiles to the tar archive |
600 |
cmd := self getCommandToAdd:colOfFiles toArchive:archivInTemp. |
|
601 |
self executeCommand:cmd directory:tempDir. |
|
1215 | 602 |
|
1246 | 603 |
"/ copy tar archiv back |
604 |
archivInTemp copyTo:archivFile. |
|
605 |
] ensure:[ |
|
606 |
"/ cg: remove the tempFile |
|
607 |
archivInTemp remove. |
|
608 |
"/ cg: remove copied files |
|
609 |
colOfFiles do:[:file | |
|
610 |
(tempDir construct:(file asFilename baseName)) remove. |
|
611 |
]. |
|
612 |
]. |
|
1215 | 613 |
! |
614 |
||
615 |
extractFiles:aColOfFilesOrNil to:aDirectory |
|
616 |
|execDir cmd| |
|
617 |
||
618 |
execDir := self fileName directory. |
|
619 |
cmd := self getCommandToExtractFiles:aColOfFilesOrNil intoDirectory:aDirectory. |
|
620 |
self executeCommand:cmd directory:execDir. |
|
1085 | 621 |
! |
622 |
||
1215 | 623 |
extractFiles:aColOfFiles withoutDirectoryTo:aDirectory |
624 |
|execDir tempDir tempFile targetFile| |
|
625 |
||
626 |
execDir := self fileName directory. |
|
627 |
tempDir := self temporaryDirectory. |
|
628 |
self extractFiles:aColOfFiles to:tempDir. |
|
629 |
||
630 |
aColOfFiles do:[ : aFileString | |
|
631 |
tempFile := self temporaryDirectory construct:aFileString. |
|
632 |
targetFile := aDirectory construct:(aFileString asFilename baseName). |
|
633 |
targetFile exists ifTrue:[ |
|
634 |
targetFile recursiveRemove. |
|
635 |
]. |
|
636 |
tempFile exists ifTrue:[ |
|
637 |
tempFile recursiveCopyTo:targetFile. |
|
638 |
]. |
|
639 |
]. |
|
1085 | 640 |
! |
641 |
||
1215 | 642 |
removeFilesFromArchive:aColOfFiles |
643 |
||
644 |
|cmd| |
|
645 |
||
646 |
cmd := self getCommandToRemoveFiles:aColOfFiles. |
|
647 |
self executeCommand:cmd directory:(self fileName directory). |
|
648 |
! ! |
|
649 |
||
650 |
!Archiver::MultiFileArchive methodsFor:'command strings'! |
|
651 |
||
652 |
getCommandToAdd:colOfFiles toArchive:archivIn |
|
653 |
self subclassResponsibility |
|
654 |
! |
|
655 |
||
656 |
getCommandToExtractFiles:sel intoDirectory:dir |
|
657 |
self subclassResponsibility |
|
658 |
! |
|
659 |
||
660 |
getCommandToListFiles:aColOfFiles |
|
661 |
self subclassResponsibility |
|
662 |
! |
|
663 |
||
664 |
getCommandToRemoveFiles:aColOfFiles |
|
665 |
self subclassResponsibility |
|
1085 | 666 |
! ! |
667 |
||
668 |
!Archiver::TarArchive class methodsFor:'command strings'! |
|
669 |
||
1215 | 670 |
tarCommand |
1085 | 671 |
^ 'tar' |
672 |
! ! |
|
673 |
||
1086 | 674 |
!Archiver::TarArchive class methodsFor:'queries'! |
675 |
||
676 |
canAddFiles |
|
677 |
||
678 |
^ true |
|
679 |
! |
|
680 |
||
681 |
canRemoveFiles |
|
682 |
||
683 |
^ true |
|
1106 | 684 |
! |
685 |
||
686 |
canViewFile |
|
687 |
||
688 |
^ true |
|
1086 | 689 |
! ! |
690 |
||
1246 | 691 |
!Archiver::TarArchive methodsFor:'columns'! |
692 |
||
693 |
columns |
|
694 |
||
1247 | 695 |
"/ colums id/readSelector words to read |
1246 | 696 |
^ #( #(#permissions 1) |
697 |
#(#ownerGroup 1) |
|
698 |
#(#size 1) |
|
699 |
#(#dateAndTime 2) |
|
700 |
#(#fileName #rest) |
|
701 |
) |
|
702 |
! |
|
703 |
||
704 |
isValidOutputLine:line |
|
705 |
('[-d][-r][-w][-x]' match:(line copyTo:4)) ifTrue:[^ true]. |
|
706 |
^ false. |
|
707 |
! ! |
|
708 |
||
1085 | 709 |
!Archiver::TarArchive methodsFor:'command strings'! |
710 |
||
1215 | 711 |
getCommandToAdd:aColOfFiles toArchive:archiveFile |
1174 | 712 |
|stream| |
1085 | 713 |
|
1215 | 714 |
archiveFile exists ifFalse:[^ nil]. |
1174 | 715 |
|
716 |
stream := WriteStream on:''. |
|
1145 | 717 |
|
1174 | 718 |
"/ 'r' TarArchivAddOption |
719 |
"/ 'f' TarArchivFileOption |
|
1246 | 720 |
stream nextPutAll:('%1 rf "%2"' |
1215 | 721 |
bindWith:self class tarCommand |
722 |
with:archiveFile asString string). |
|
1145 | 723 |
|
1174 | 724 |
stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
725 |
^ stream contents |
|
1085 | 726 |
! |
727 |
||
1215 | 728 |
getCommandToExtractFiles:sel intoDirectory:dir |
1174 | 729 |
|stream| |
1085 | 730 |
|
731 |
stream := WriteStream on:''. |
|
1145 | 732 |
|
733 |
"/ 'x' TarArchivUnpackOption |
|
734 |
"/ 'f' TarArchivFileOption |
|
735 |
"/ 'C' TarArchivUnpackInDirectoryOption |
|
736 |
stream nextPutAll:('%1 -xf "%2" -C %3' |
|
1215 | 737 |
bindWith:self class tarCommand |
1145 | 738 |
with:self fileName asString string |
739 |
with:dir asString). |
|
740 |
||
1085 | 741 |
sel notNil ifTrue:[ |
742 |
sel do:[:el | |
|
1145 | 743 |
stream nextPutAll:' "'. |
744 |
stream nextPutAll:(el asString). |
|
745 |
stream nextPutAll:'"' |
|
1085 | 746 |
]. |
747 |
]. |
|
1145 | 748 |
^ stream contents. |
1085 | 749 |
! |
750 |
||
1215 | 751 |
getCommandToListFiles:aColOfFiles |
1174 | 752 |
|stream| |
1085 | 753 |
|
754 |
stream := WriteStream on:''. |
|
1145 | 755 |
|
756 |
"/ 't' TarArchivListContentsOption |
|
757 |
"/ 'v' TarArchivVerboseOption |
|
758 |
"/ 'f' TarArchivFileOption |
|
759 |
stream nextPutAll:('%1 -tvf "%2"' |
|
1215 | 760 |
bindWith:self class tarCommand |
1145 | 761 |
with:self fileName baseName). |
762 |
||
1174 | 763 |
stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
1145 | 764 |
^ stream contents. |
1085 | 765 |
! |
766 |
||
1215 | 767 |
getCommandToRemoveFiles:sel |
1174 | 768 |
|stream filename| |
1085 | 769 |
|
770 |
filename := self fileName. |
|
1174 | 771 |
filename exists ifFalse:[^ nil]. |
1145 | 772 |
|
1174 | 773 |
stream := WriteStream on:''. |
1145 | 774 |
|
1174 | 775 |
"/ 'f' TarArchivFileOption |
776 |
stream nextPutAll:('%1 --delete -f "%2"' |
|
1215 | 777 |
bindWith:self class tarCommand |
1174 | 778 |
with:self fileName baseName). |
779 |
||
780 |
stream nextPutAll:(self class stringWithQuotedFileBaseNames:sel). |
|
781 |
^ stream contents |
|
1085 | 782 |
! ! |
783 |
||
1086 | 784 |
!Archiver::TarGZipArchive class methodsFor:'queries'! |
785 |
||
786 |
canAddFiles |
|
787 |
||
788 |
^ Archiver tarArchive canAddFiles |
|
789 |
! |
|
790 |
||
791 |
canRemoveFiles |
|
792 |
||
793 |
^ Archiver tarArchive canRemoveFiles |
|
1106 | 794 |
! |
795 |
||
796 |
canViewFile |
|
797 |
||
798 |
^ Archiver tarArchive canViewFile |
|
1086 | 799 |
! ! |
800 |
||
1085 | 801 |
!Archiver::TarGZipArchive methodsFor:'accessing'! |
802 |
||
803 |
fileName:aFile |
|
804 |
||
805 |
| tempDir file gzipArchiver suffix| |
|
806 |
||
807 |
super fileName:aFile. |
|
808 |
" unzip file in tempDirectory and do all the things with tar file " |
|
809 |
tempDir := self temporaryDirectory. |
|
810 |
gzipArchiver := Archiver::GZipArchive with:(self fileName). |
|
811 |
gzipArchiver unzipTo:tempDir. |
|
812 |
suffix := self fileName suffix. |
|
813 |
file := self fileName withoutSuffix. |
|
814 |
file := file baseName. |
|
815 |
suffix = 'tgz' ifTrue:[ |
|
816 |
file := file , '.tar' |
|
817 |
]. |
|
818 |
tarFile := self temporaryDirectory construct:file. |
|
1215 | 819 |
tarArchiver := Archiver::TarArchive with:tarFile. |
1085 | 820 |
! ! |
821 |
||
822 |
!Archiver::TarGZipArchive methodsFor:'actions'! |
|
823 |
||
1174 | 824 |
addFilesToArchive:colOfFiles |
1085 | 825 |
|
826 |
self setCommandOptions. |
|
1174 | 827 |
tarArchiver addFilesToArchive:colOfFiles. |
1098 | 828 |
"/ synchronize the tar archive under temporary file with archiv file position |
1085 | 829 |
self synchronize. |
830 |
! |
|
831 |
||
1215 | 832 |
extractFiles:aColOfFiles to:aDirectory |
1085 | 833 |
|
834 |
self setCommandOptions. |
|
1215 | 835 |
tarArchiver extractFiles:aColOfFiles to:aDirectory. |
1085 | 836 |
! |
837 |
||
1246 | 838 |
extractFiles:aColOfFiles withoutDirectoryTo:aDirectory |
1085 | 839 |
|
840 |
self setCommandOptions. |
|
1246 | 841 |
tarArchiver extractFiles:aColOfFiles withoutDirectoryTo:aDirectory. |
1085 | 842 |
! |
843 |
||
1215 | 844 |
listFiles:aColOfFiles |
1085 | 845 |
self setCommandOptions. |
1215 | 846 |
tarArchiver listFiles:aColOfFiles. |
1085 | 847 |
! |
848 |
||
1174 | 849 |
removeFilesFromArchive:aColOfFiles |
1085 | 850 |
|
851 |
self setCommandOptions. |
|
1174 | 852 |
tarArchiver removeFilesFromArchive:aColOfFiles. |
1085 | 853 |
self synchronize. |
854 |
! ! |
|
855 |
||
856 |
!Archiver::TarGZipArchive methodsFor:'actions private'! |
|
857 |
||
858 |
setCommandOptions |
|
859 |
||
860 |
tarArchiver outStream:(self outStream). |
|
861 |
tarArchiver errorStream:(self errorStream). |
|
862 |
tarArchiver synchron:(self synchron). |
|
863 |
! |
|
864 |
||
865 |
synchronize |
|
866 |
||
867 |
|gzipArchiver| |
|
868 |
||
1174 | 869 |
gzipArchiver := Archiver::GZipArchive with:nil. |
1085 | 870 |
gzipArchiver zipFile:(tarArchiver fileName) to:(self fileName). |
871 |
! ! |
|
872 |
||
1246 | 873 |
!Archiver::TarGZipArchive methodsFor:'columns'! |
874 |
||
875 |
columns |
|
876 |
^ tarArchiver columns |
|
877 |
! |
|
878 |
||
879 |
isValidOutputLine:line |
|
880 |
^ tarArchiver isValidOutputLine:line |
|
881 |
! ! |
|
882 |
||
1085 | 883 |
!Archiver::TarGZipArchive methodsFor:'initialization & release'! |
884 |
||
885 |
release |
|
886 |
||
887 |
super release. |
|
888 |
tarArchiver release. |
|
889 |
! ! |
|
890 |
||
1086 | 891 |
!Archiver::ZipArchive class methodsFor:'command strings'! |
892 |
||
1215 | 893 |
unzipCommand |
1086 | 894 |
^ 'unzip' |
895 |
! |
|
896 |
||
1215 | 897 |
zipCommand |
898 |
^ 'zip' |
|
1086 | 899 |
! ! |
900 |
||
901 |
!Archiver::ZipArchive class methodsFor:'queries'! |
|
902 |
||
903 |
canAddFiles |
|
904 |
||
905 |
^ true |
|
906 |
! |
|
907 |
||
908 |
canRemoveFiles |
|
909 |
||
910 |
^ true |
|
1088 | 911 |
! |
912 |
||
1138
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
913 |
canViewFile |
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
914 |
|
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
915 |
^ true |
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
916 |
! |
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
917 |
|
1088 | 918 |
hasLastLine |
919 |
^ true |
|
920 |
! |
|
921 |
||
922 |
hasTitleLine |
|
923 |
^ true |
|
1086 | 924 |
! ! |
925 |
||
1246 | 926 |
!Archiver::ZipArchive methodsFor:'columns'! |
927 |
||
928 |
columns |
|
929 |
||
1247 | 930 |
"/ colums id/readSelector words to read |
1246 | 931 |
^ #( (#permissions 1) |
932 |
(#version 2) |
|
933 |
(#size 1) |
|
934 |
(#type 1) |
|
935 |
(#ratio 1) |
|
936 |
(nil 1) |
|
937 |
(#dateAndTime 2) |
|
938 |
(#fileName #rest) |
|
939 |
) |
|
940 |
! |
|
941 |
||
942 |
isValidOutputLine:line |
|
943 |
('[-d][-r][-w][-x]' match:(line copyTo:4)) ifTrue:[^ true]. |
|
944 |
^ false. |
|
945 |
! ! |
|
946 |
||
1086 | 947 |
!Archiver::ZipArchive methodsFor:'command strings'! |
948 |
||
1215 | 949 |
getCommandToAdd:aColOfFiles toArchive:archiveFile |
950 |
|stream| |
|
1086 | 951 |
|
1215 | 952 |
archiveFile exists ifFalse:[^ nil]. |
1088 | 953 |
|
1215 | 954 |
stream := WriteStream on:''. |
955 |
||
956 |
stream nextPutAll:('%1 -r "%2"' |
|
957 |
bindWith:self class zipCommand |
|
958 |
with:archiveFile asString string). |
|
1088 | 959 |
|
1246 | 960 |
self |
961 |
addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName]) |
|
962 |
toStream:stream. |
|
1215 | 963 |
|
964 |
^ stream contents |
|
1086 | 965 |
! |
966 |
||
1246 | 967 |
getCommandToExtractFiles:aColOfFiles intoDirectory:dir |
1145 | 968 |
|stream| |
1087 | 969 |
|
970 |
stream := WriteStream on:''. |
|
1145 | 971 |
|
972 |
"/ -o UnzipOverwriteExistingFilesOption |
|
973 |
"/ -d UnzipExtDirectoryOption |
|
1087 | 974 |
|
1145 | 975 |
stream nextPutAll:('%1 -o -d "%2" "%3"' |
1215 | 976 |
bindWith:self class unzipCommand |
1145 | 977 |
with:dir asString string |
978 |
with:self fileName asString). |
|
1086 | 979 |
|
1246 | 980 |
self addDoubleQuotedFilenames:aColOfFiles toStream:stream. |
1145 | 981 |
^ stream contents. |
1086 | 982 |
! |
983 |
||
1215 | 984 |
getCommandToListFiles:aColOfFiles |
1144 | 985 |
|stream| |
1086 | 986 |
|
987 |
stream := WriteStream on:''. |
|
1144 | 988 |
|
1215 | 989 |
"/ -Z ZipInfoOption |
1144 | 990 |
"/ -h ZipHeaderOption |
991 |
"/ -t ZipTotalOption |
|
1215 | 992 |
stream nextPutAll:('%1 -Z -m -h "%2"' |
993 |
bindWith:self class unzipCommand |
|
1144 | 994 |
with:self fileName asString string). |
1139 | 995 |
|
1246 | 996 |
aColOfFiles notNil ifTrue:[ self halt. |
997 |
self |
|
998 |
addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName]) |
|
999 |
toStream:stream. |
|
1086 | 1000 |
]. |
1144 | 1001 |
^ stream contents. |
1086 | 1002 |
! |
1003 |
||
1215 | 1004 |
getCommandToRemoveFiles:aColOfFiles |
1145 | 1005 |
|stream| |
1088 | 1006 |
|
1007 |
stream := WriteStream on:''. |
|
1008 |
||
1145 | 1009 |
stream nextPutAll:('%1 -d "%2"' |
1215 | 1010 |
bindWith:self class zipCommand |
1145 | 1011 |
with:self fileName asString string). |
1088 | 1012 |
|
1246 | 1013 |
self addDoubleQuotedFilenames:aColOfFiles toStream:stream. |
1145 | 1014 |
^ stream contents. |
1086 | 1015 |
! ! |
1016 |
||
1085 | 1017 |
!Archiver class methodsFor:'documentation'! |
1018 |
||
1019 |
version |
|
1334 | 1020 |
^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.20 2003-10-21 07:21:31 cg Exp $' |
1085 | 1021 |
! ! |