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