author | Claus Gittinger <cg@exept.de> |
Fri, 09 May 2003 23:13:45 +0200 | |
changeset 1205 | 5042e93c6796 |
parent 1174 | fde4f57dce18 |
child 1215 | c3fe5597c1ec |
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 |
| cmd dir| |
320 |
||
321 |
self fileName isNil ifTrue:[ ^ self]. |
|
1205 | 322 |
"/ dir := self fileName directory. |
323 |
^ Array |
|
324 |
with: (self fileName withoutSuffix) |
|
1086 | 325 |
! |
326 |
||
1174 | 327 |
listFilesFromArchive:aCol |
1086 | 328 |
|
1174 | 329 |
self listFilesFromArchive |
1086 | 330 |
! |
331 |
||
1085 | 332 |
unzipTo:aDirectory |
333 |
||
334 |
| cmd file newFile| |
|
335 |
||
336 |
(aDirectory exists not) ifTrue:[ |
|
337 |
DialogBox warn:'cant unzip to not existing directory ', aDirectory asString. |
|
338 |
]. |
|
339 |
(aDirectory isDirectory not) ifTrue:[ |
|
340 |
DialogBox warn:'cant unzip to file ', aDirectory asString. |
|
341 |
]. |
|
342 |
file := self fileName. |
|
343 |
(file directory asString = aDirectory asString) ifFalse:[ |
|
344 |
file copyTo:(aDirectory construct:(file baseName)). |
|
345 |
]. |
|
346 |
newFile := aDirectory construct:(file baseName). |
|
347 |
cmd := self getUnzipCommandForFile:newFile. |
|
348 |
self executeCommand:cmd directory:aDirectory. |
|
349 |
! |
|
350 |
||
351 |
zipFile:aFile to:newFile |
|
352 |
||
353 |
| cmd directory| |
|
354 |
||
355 |
directory := newFile directory. |
|
356 |
(directory exists not) ifTrue:[ |
|
357 |
DialogBox warn:'cant unzip to not existing directory ', directory asString. |
|
358 |
]. |
|
359 |
(directory isDirectory not) ifTrue:[ |
|
360 |
DialogBox warn:'cant unzip to file ', directory asString. |
|
361 |
]. |
|
362 |
cmd := self getZipCommandForFile:aFile to:newFile. |
|
363 |
self executeCommand:cmd directory:directory. |
|
364 |
newFile exists ifTrue:[ |
|
365 |
self fileName:newFile. |
|
366 |
]. |
|
367 |
! ! |
|
368 |
||
369 |
!Archiver::GZipArchive methodsFor:'command strings'! |
|
370 |
||
1086 | 371 |
getFileListFromArchivCommand |
1174 | 372 |
^ 'gzip -l -v %1' bindWith:self fileName baseName |
1086 | 373 |
! |
374 |
||
1085 | 375 |
getUnzipCommand |
1174 | 376 |
^ self getUnzipCommandForFile:(self fileName baseName) |
1085 | 377 |
! |
378 |
||
1174 | 379 |
getUnzipCommandForFile:aFileName |
380 |
^ 'gunzip %1' bindWith:aFileName asString |
|
1085 | 381 |
! |
382 |
||
383 |
getZipCommandForFile:aFileName |
|
1174 | 384 |
^ 'gzip %1' bindWith:aFileName asString |
1085 | 385 |
! |
386 |
||
387 |
getZipCommandForFile:aFile to:newFile |
|
1174 | 388 |
^ 'gzip -c %1 > %2' bindWith:aFile asString with:newFile asString |
1085 | 389 |
! ! |
390 |
||
1086 | 391 |
!Archiver::TarArchive class methodsFor:'columns'! |
392 |
||
393 |
columns |
|
394 |
||
395 |
"/ colums id words to read |
|
396 |
^ #( #(#permissions 1) |
|
397 |
#(#ownerGroup 1) |
|
398 |
#(#size 1) |
|
399 |
#(#dateAndTime 2) |
|
1125
d55d69b4b93a
fixed filename extraction (if name includes spaces)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
400 |
#(#fileName #rest) |
1086 | 401 |
) |
402 |
! ! |
|
403 |
||
1085 | 404 |
!Archiver::TarArchive class methodsFor:'command strings'! |
405 |
||
1174 | 406 |
stringWithQuotedFileBaseNames:aColOfFiles |
407 |
||
408 |
aColOfFiles isNil ifTrue:[^ '']. |
|
409 |
||
410 |
^ String |
|
411 |
streamContents:[:str | |
|
412 |
aColOfFiles do:[:fn | |
|
413 |
str nextPutAll:' "'. |
|
414 |
str nextPutAll:(fn asFilename baseName). |
|
415 |
str nextPutAll:'"'. |
|
416 |
]. |
|
417 |
] |
|
418 |
! |
|
419 |
||
420 |
tarArchiveCommand |
|
1085 | 421 |
^ 'tar' |
422 |
! ! |
|
423 |
||
1086 | 424 |
!Archiver::TarArchive class methodsFor:'queries'! |
425 |
||
426 |
canAddFiles |
|
427 |
||
428 |
^ true |
|
429 |
! |
|
430 |
||
431 |
canRemoveFiles |
|
432 |
||
433 |
^ true |
|
1106 | 434 |
! |
435 |
||
436 |
canViewFile |
|
437 |
||
438 |
^ true |
|
1086 | 439 |
! ! |
440 |
||
1085 | 441 |
!Archiver::TarArchive methodsFor:'actions'! |
442 |
||
1174 | 443 |
addFilesToArchive:colOfFiles |
1085 | 444 |
|
445 |
| cmd tempDir archivFile archivInTemp| |
|
446 |
||
447 |
tempDir := self temporaryDirectory. |
|
448 |
archivFile := self fileName. |
|
449 |
archivInTemp := tempDir construct:(archivFile baseName). |
|
450 |
"/ copy files to be added to tempDir |
|
451 |
colOfFiles do:[ :file | |
|
1088 | 452 |
file recursiveCopyTo:(tempDir construct:(file asFilename baseName)) |
1085 | 453 |
]. |
454 |
||
455 |
"/ copy tar archiv to tempDir |
|
456 |
archivFile copyTo:archivInTemp. |
|
457 |
||
458 |
"/ addFiles to the tar archive |
|
1174 | 459 |
cmd := self getAddFilesToTarArchiveCommandForArchive:archivInTemp with:colOfFiles. |
1085 | 460 |
self executeCommand:cmd directory:tempDir. |
461 |
||
462 |
"/ copy tar archiv back |
|
463 |
archivInTemp copyTo:(self fileName). |
|
464 |
! |
|
465 |
||
466 |
extractTo:aDirectory |
|
467 |
||
468 |
^ self extractTo:aDirectory with:nil |
|
469 |
! |
|
470 |
||
471 |
extractTo:aDirectory with:files |
|
472 |
||
473 |
|execDir cmd| |
|
474 |
||
475 |
execDir := self fileName directory. |
|
476 |
cmd := self getExtractSelectedFilesCommandForDirectory:aDirectory withSelection:files. |
|
477 |
self executeCommand:cmd directory:execDir. |
|
478 |
! |
|
479 |
||
480 |
extractWithOutDirectoryTo:aDirectory with:files |
|
481 |
||
482 |
|execDir tempDir tempFile| |
|
483 |
||
484 |
execDir := self fileName directory. |
|
485 |
tempDir := self temporaryDirectory. |
|
486 |
self extractTo:tempDir with:files. |
|
487 |
files do:[ : aFileString | |
|
488 |
tempFile := self temporaryDirectory construct:aFileString. |
|
489 |
tempFile exists ifTrue:[ |
|
1131 | 490 |
tempFile recursiveCopyTo:(aDirectory construct:(aFileString asFilename baseName)). |
1085 | 491 |
]. |
492 |
]. |
|
493 |
! |
|
494 |
||
1174 | 495 |
listFilesFromArchive |
1085 | 496 |
|
1174 | 497 |
self listFilesFromArchive:nil |
1085 | 498 |
! |
499 |
||
1174 | 500 |
listFilesFromArchive:newColOfFiles |
1085 | 501 |
|
502 |
| cmd dir| |
|
503 |
||
504 |
self fileName isNil ifTrue:[ ^ self]. |
|
505 |
dir := self fileName directory. |
|
1174 | 506 |
cmd := self getFileListFromArchiveCommand:newColOfFiles. |
1085 | 507 |
self executeCommand:cmd directory:dir |
508 |
! |
|
509 |
||
1174 | 510 |
removeFilesFromArchive:aColOfFiles |
1085 | 511 |
|
512 |
|cmd| |
|
513 |
||
1174 | 514 |
cmd := self getRemoveFilesFromTarArchiveCommandFor:aColOfFiles. |
1085 | 515 |
self executeCommand:cmd directory:(self fileName directory). |
516 |
! ! |
|
517 |
||
518 |
!Archiver::TarArchive methodsFor:'command strings'! |
|
519 |
||
1174 | 520 |
getAddFilesToTarArchiveCommandForArchive:archivFile with:aColOfFiles |
521 |
|stream| |
|
1085 | 522 |
|
1174 | 523 |
archivFile exists ifFalse:[^ nil]. |
524 |
||
525 |
stream := WriteStream on:''. |
|
1145 | 526 |
|
1174 | 527 |
"/ 'r' TarArchivAddOption |
528 |
"/ 'f' TarArchivFileOption |
|
529 |
stream nextPutAll:('%1 -rf "%2"' |
|
530 |
bindWith:self class tarArchiveCommand |
|
531 |
with:archivFile asString string). |
|
1145 | 532 |
|
1174 | 533 |
stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
534 |
^ stream contents |
|
1085 | 535 |
! |
536 |
||
537 |
getExtractSelectedFilesCommandForDirectory:dir withSelection:sel |
|
1174 | 538 |
|stream| |
1085 | 539 |
|
540 |
stream := WriteStream on:''. |
|
1145 | 541 |
|
542 |
"/ 'x' TarArchivUnpackOption |
|
543 |
"/ 'f' TarArchivFileOption |
|
544 |
"/ 'C' TarArchivUnpackInDirectoryOption |
|
545 |
stream nextPutAll:('%1 -xf "%2" -C %3' |
|
1174 | 546 |
bindWith:self class tarArchiveCommand |
1145 | 547 |
with:self fileName asString string |
548 |
with:dir asString). |
|
549 |
||
1085 | 550 |
sel notNil ifTrue:[ |
551 |
sel do:[:el | |
|
1145 | 552 |
stream nextPutAll:' "'. |
553 |
stream nextPutAll:(el asString). |
|
554 |
stream nextPutAll:'"' |
|
1085 | 555 |
]. |
556 |
]. |
|
1145 | 557 |
^ stream contents. |
1085 | 558 |
! |
559 |
||
1174 | 560 |
getFileListFromArchiveCommand:aColOfFiles |
561 |
|stream| |
|
1085 | 562 |
|
563 |
stream := WriteStream on:''. |
|
1145 | 564 |
|
565 |
"/ 't' TarArchivListContentsOption |
|
566 |
"/ 'v' TarArchivVerboseOption |
|
567 |
"/ 'f' TarArchivFileOption |
|
568 |
stream nextPutAll:('%1 -tvf "%2"' |
|
1174 | 569 |
bindWith:self class tarArchiveCommand |
1145 | 570 |
with:self fileName baseName). |
571 |
||
1174 | 572 |
stream nextPutAll:(self class stringWithQuotedFileBaseNames:aColOfFiles). |
1145 | 573 |
^ stream contents. |
1085 | 574 |
! |
575 |
||
1174 | 576 |
getRemoveFilesFromTarArchiveCommandFor:sel |
577 |
|stream filename| |
|
1085 | 578 |
|
579 |
filename := self fileName. |
|
1174 | 580 |
filename exists ifFalse:[^ nil]. |
1145 | 581 |
|
1174 | 582 |
stream := WriteStream on:''. |
1145 | 583 |
|
1174 | 584 |
"/ 'f' TarArchivFileOption |
585 |
stream nextPutAll:('%1 --delete -f "%2"' |
|
586 |
bindWith:self class tarArchiveCommand |
|
587 |
with:self fileName baseName). |
|
588 |
||
589 |
stream nextPutAll:(self class stringWithQuotedFileBaseNames:sel). |
|
590 |
^ stream contents |
|
1085 | 591 |
! ! |
592 |
||
1086 | 593 |
!Archiver::TarGZipArchive class methodsFor:'columns'! |
594 |
||
595 |
columns |
|
596 |
||
597 |
^ Archiver tarArchive columns |
|
598 |
! ! |
|
599 |
||
600 |
!Archiver::TarGZipArchive class methodsFor:'queries'! |
|
601 |
||
602 |
canAddFiles |
|
603 |
||
604 |
^ Archiver tarArchive canAddFiles |
|
605 |
! |
|
606 |
||
607 |
canRemoveFiles |
|
608 |
||
609 |
^ Archiver tarArchive canRemoveFiles |
|
1106 | 610 |
! |
611 |
||
612 |
canViewFile |
|
613 |
||
614 |
^ Archiver tarArchive canViewFile |
|
1086 | 615 |
! ! |
616 |
||
1085 | 617 |
!Archiver::TarGZipArchive methodsFor:'accessing'! |
618 |
||
619 |
fileName:aFile |
|
620 |
||
621 |
| tempDir file gzipArchiver suffix| |
|
622 |
||
623 |
super fileName:aFile. |
|
624 |
" unzip file in tempDirectory and do all the things with tar file " |
|
625 |
tempDir := self temporaryDirectory. |
|
626 |
gzipArchiver := Archiver::GZipArchive with:(self fileName). |
|
627 |
gzipArchiver unzipTo:tempDir. |
|
628 |
suffix := self fileName suffix. |
|
629 |
file := self fileName withoutSuffix. |
|
630 |
file := file baseName. |
|
631 |
suffix = 'tgz' ifTrue:[ |
|
632 |
file := file , '.tar' |
|
633 |
]. |
|
634 |
tarFile := self temporaryDirectory construct:file. |
|
1088 | 635 |
tarArchiver := Archiver tarArchive with:tarFile. |
1085 | 636 |
! ! |
637 |
||
638 |
!Archiver::TarGZipArchive methodsFor:'actions'! |
|
639 |
||
1174 | 640 |
addFilesToArchive:colOfFiles |
1085 | 641 |
|
642 |
self setCommandOptions. |
|
1174 | 643 |
tarArchiver addFilesToArchive:colOfFiles. |
1098 | 644 |
"/ synchronize the tar archive under temporary file with archiv file position |
1085 | 645 |
self synchronize. |
646 |
! |
|
647 |
||
648 |
extractTo:aDirectory |
|
649 |
||
650 |
self extractTo:aDirectory with:nil. |
|
651 |
! |
|
652 |
||
653 |
extractTo:aDirectory with:col |
|
654 |
||
655 |
self setCommandOptions. |
|
656 |
tarArchiver extractTo:aDirectory with:col. |
|
657 |
! |
|
658 |
||
659 |
extractWithOutDirectoryTo:aDirectory with:files |
|
660 |
||
661 |
self setCommandOptions. |
|
662 |
tarArchiver extractWithOutDirectoryTo:aDirectory with:files. |
|
663 |
! |
|
664 |
||
1174 | 665 |
listFilesFromArchive |
1085 | 666 |
|
1174 | 667 |
self listFilesFromArchive:nil |
1085 | 668 |
! |
669 |
||
1174 | 670 |
listFilesFromArchive:newColOfFiles |
1085 | 671 |
|
672 |
self setCommandOptions. |
|
1174 | 673 |
^ tarArchiver listFilesFromArchive:newColOfFiles. |
1085 | 674 |
! |
675 |
||
1174 | 676 |
removeFilesFromArchive:aColOfFiles |
1085 | 677 |
|
678 |
self setCommandOptions. |
|
1174 | 679 |
tarArchiver removeFilesFromArchive:aColOfFiles. |
1085 | 680 |
self synchronize. |
681 |
! ! |
|
682 |
||
683 |
!Archiver::TarGZipArchive methodsFor:'actions private'! |
|
684 |
||
685 |
setCommandOptions |
|
686 |
||
687 |
tarArchiver outStream:(self outStream). |
|
688 |
tarArchiver errorStream:(self errorStream). |
|
689 |
tarArchiver synchron:(self synchron). |
|
690 |
! |
|
691 |
||
692 |
synchronize |
|
693 |
||
694 |
|gzipArchiver| |
|
695 |
||
1174 | 696 |
gzipArchiver := Archiver::GZipArchive with:nil. |
1085 | 697 |
gzipArchiver zipFile:(tarArchiver fileName) to:(self fileName). |
698 |
! ! |
|
699 |
||
700 |
!Archiver::TarGZipArchive methodsFor:'initialization & release'! |
|
701 |
||
702 |
release |
|
703 |
||
704 |
super release. |
|
705 |
tarArchiver release. |
|
706 |
! ! |
|
707 |
||
1086 | 708 |
!Archiver::ZipArchive class methodsFor:'columns'! |
709 |
||
710 |
columns |
|
711 |
||
712 |
"/ colums id words to read |
|
713 |
^ #( #(#permissions 1) |
|
714 |
#(#version 2) |
|
715 |
#(#size 1) |
|
716 |
#(#type 1) |
|
717 |
#(#ratio 1) |
|
718 |
#(#dateAndTime 2) |
|
1125
d55d69b4b93a
fixed filename extraction (if name includes spaces)
Claus Gittinger <cg@exept.de>
parents:
1106
diff
changeset
|
719 |
#(#fileName #rest) |
1086 | 720 |
) |
721 |
! ! |
|
722 |
||
723 |
!Archiver::ZipArchive class methodsFor:'command strings'! |
|
724 |
||
1174 | 725 |
ZipArchiveCommand |
1086 | 726 |
^ 'zip' |
727 |
! |
|
728 |
||
729 |
ZipListCommand |
|
730 |
^ 'unzip' |
|
731 |
! |
|
732 |
||
733 |
ZipUnzipCommand |
|
734 |
^ 'unzip' |
|
735 |
! ! |
|
736 |
||
737 |
!Archiver::ZipArchive class methodsFor:'queries'! |
|
738 |
||
739 |
canAddFiles |
|
740 |
||
741 |
^ true |
|
742 |
! |
|
743 |
||
744 |
canRemoveFiles |
|
745 |
||
746 |
^ true |
|
1088 | 747 |
! |
748 |
||
1138
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
749 |
canViewFile |
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
750 |
|
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
751 |
^ true |
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
752 |
! |
5232eb3c94e0
canView is true for ZipArchives
Claus Gittinger <cg@exept.de>
parents:
1131
diff
changeset
|
753 |
|
1088 | 754 |
hasLastLine |
755 |
||
756 |
^ true |
|
757 |
! |
|
758 |
||
759 |
hasTitleLine |
|
760 |
||
761 |
^ true |
|
1086 | 762 |
! ! |
763 |
||
764 |
!Archiver::ZipArchive methodsFor:'actions'! |
|
765 |
||
1174 | 766 |
addFilesToArchive:colOfFiles |
1087 | 767 |
|
768 |
|cmd tempDir archivFile archivInTemp| |
|
769 |
||
770 |
tempDir := self temporaryDirectory. |
|
771 |
archivFile := self fileName. |
|
772 |
archivInTemp := tempDir construct:(archivFile baseName). |
|
773 |
"/ copy files to be added to tempDir |
|
774 |
colOfFiles do:[ :file | |
|
1088 | 775 |
file recursiveCopyTo:(tempDir construct:(file asFilename baseName)) |
1087 | 776 |
]. |
777 |
||
778 |
"/ copy archiv to tempDir |
|
779 |
archivFile copyTo:archivInTemp. |
|
780 |
||
781 |
"/ addFiles to the tar archive |
|
782 |
cmd := self getAddFilesToArchiveCommandForArchiv:archivInTemp with:colOfFiles. |
|
1088 | 783 |
self executeCommand:cmd directory:tempDir. |
1087 | 784 |
|
785 |
"/ copy tar archiv back |
|
786 |
archivInTemp copyTo:(self fileName). |
|
1086 | 787 |
! |
788 |
||
789 |
extractTo:aDirectory |
|
790 |
||
791 |
^ self extractTo:aDirectory with:nil |
|
792 |
! |
|
793 |
||
794 |
extractTo:aDirectory with:files |
|
1087 | 795 |
|
796 |
|execDir cmd| |
|
797 |
||
798 |
execDir := self fileName directory. |
|
799 |
cmd := self getExtractSelectedFilesCommandForDirectory:aDirectory withSelection:files. |
|
800 |
self executeCommand:cmd directory:execDir. |
|
1086 | 801 |
! |
802 |
||
803 |
extractWithOutDirectoryTo:aDirectory with:files |
|
1087 | 804 |
|
1088 | 805 |
|execDir tempDir tempFile targetFile| |
1087 | 806 |
|
807 |
execDir := self fileName directory. |
|
808 |
tempDir := self temporaryDirectory. |
|
809 |
self extractTo:tempDir with:files. |
|
1088 | 810 |
self halt. |
1087 | 811 |
files do:[ : aFileString | |
812 |
tempFile := self temporaryDirectory construct:aFileString. |
|
1088 | 813 |
targetFile := aDirectory construct:(aFileString asFilename baseName). |
814 |
targetFile exists ifTrue:[ |
|
815 |
targetFile recursiveRemove. |
|
816 |
]. |
|
1087 | 817 |
tempFile exists ifTrue:[ |
1088 | 818 |
tempFile recursiveCopyTo:targetFile. |
1087 | 819 |
]. |
820 |
]. |
|
1086 | 821 |
! |
822 |
||
1174 | 823 |
listFilesFromArchive |
1086 | 824 |
|
1174 | 825 |
self listFilesFromArchive:nil |
1086 | 826 |
! |
827 |
||
1174 | 828 |
listFilesFromArchive:newColOfFiles |
1086 | 829 |
|
830 |
|dir cmd| |
|
831 |
||
832 |
self fileName isNil ifTrue:[ ^ self]. |
|
833 |
dir := self fileName directory. |
|
1174 | 834 |
cmd := self getFileListFromArchiveCommand:newColOfFiles. |
1086 | 835 |
self executeCommand:cmd directory:dir |
836 |
! |
|
837 |
||
1174 | 838 |
removeFilesFromArchive:aColOfFiles |
1088 | 839 |
|
840 |
|cmd| |
|
841 |
||
1174 | 842 |
cmd := self getRemoveFilesFromArchiveFor:aColOfFiles. |
1088 | 843 |
self executeCommand:cmd directory:(self fileName directory). |
1086 | 844 |
! ! |
845 |
||
846 |
!Archiver::ZipArchive methodsFor:'command strings'! |
|
847 |
||
1174 | 848 |
getAddFilesToArchiveCommandForArchive:archiveFile with:aColOfFiles |
1086 | 849 |
| cmd stream| |
850 |
||
1174 | 851 |
archiveFile exists ifTrue:[ |
1086 | 852 |
stream := WriteStream on:''. |
1145 | 853 |
|
854 |
stream nextPutAll:('%1 -r "%2"' |
|
1174 | 855 |
bindWith:self class ZipArchiveCommand |
856 |
with:archiveFile asString string). |
|
1088 | 857 |
|
1145 | 858 |
aColOfFiles do:[:el | |
859 |
stream nextPutAll:' "'. |
|
860 |
stream nextPutAll:(el asFilename baseName). |
|
861 |
stream nextPutAll:'"' |
|
862 |
]. |
|
1088 | 863 |
|
1086 | 864 |
cmd := stream contents |
865 |
]. |
|
866 |
^ cmd |
|
867 |
! |
|
868 |
||
1145 | 869 |
getExtractSelectedFilesCommandForDirectory:dir withSelection:sel |
870 |
|stream| |
|
1087 | 871 |
|
872 |
stream := WriteStream on:''. |
|
1145 | 873 |
|
874 |
"/ -o UnzipOverwriteExistingFilesOption |
|
875 |
"/ -d UnzipExtDirectoryOption |
|
1087 | 876 |
|
1145 | 877 |
stream nextPutAll:('%1 -o -d "%2" "%3"' |
878 |
bindWith:self class ZipUnzipCommand |
|
879 |
with:dir asString string |
|
880 |
with:self fileName asString). |
|
1086 | 881 |
|
882 |
sel notNil ifTrue:[ |
|
883 |
sel do:[:el | |
|
1145 | 884 |
stream nextPutAll:' "'. |
885 |
stream nextPutAll:(el asString). |
|
886 |
stream nextPutAll:'"' |
|
1086 | 887 |
]. |
888 |
]. |
|
1145 | 889 |
^ stream contents. |
1086 | 890 |
! |
891 |
||
1174 | 892 |
getFileListFromArchiveCommand:aColOfFiles |
1144 | 893 |
|stream| |
1086 | 894 |
|
895 |
stream := WriteStream on:''. |
|
1144 | 896 |
|
897 |
"/ -Z ZipListOption |
|
898 |
"/ -h ZipHeaderOption |
|
899 |
"/ -t ZipTotalOption |
|
900 |
stream nextPutAll:('%1 -Z -h -t "%2"' |
|
901 |
bindWith:self class ZipUnzipCommand |
|
902 |
with:self fileName asString string). |
|
1139 | 903 |
|
1086 | 904 |
aColOfFiles notNil ifTrue:[ |
905 |
aColOfFiles do:[:el | |
|
1144 | 906 |
stream nextPutAll:' "'. |
907 |
stream nextPutAll:(el baseName). |
|
908 |
stream nextPutAll:'"' |
|
1086 | 909 |
] |
910 |
]. |
|
1144 | 911 |
^ stream contents. |
1086 | 912 |
! |
913 |
||
1174 | 914 |
getRemoveFilesFromArchiveFor:sel |
1145 | 915 |
|stream| |
1088 | 916 |
|
917 |
stream := WriteStream on:''. |
|
918 |
||
1145 | 919 |
stream nextPutAll:('%1 -d "%2"' |
1174 | 920 |
bindWith:self class ZipArchiveCommand |
1145 | 921 |
with:self fileName asString string). |
1088 | 922 |
|
1145 | 923 |
sel do:[:el | |
924 |
stream nextPutAll:' "'. |
|
925 |
stream nextPutAll:(el asString). |
|
926 |
stream nextPutAll:'"' |
|
927 |
]. |
|
928 |
^ stream contents. |
|
1086 | 929 |
! ! |
930 |
||
1085 | 931 |
!Archiver class methodsFor:'documentation'! |
932 |
||
933 |
version |
|
1205 | 934 |
^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.15 2003-05-09 21:13:45 cg Exp $' |
1085 | 935 |
! ! |