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