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 |
|
|
73 |
!Archiver class methodsFor:'common options'!
|
|
74 |
|
|
75 |
MinusSign
|
|
76 |
|
|
77 |
^ $-
|
|
78 |
!
|
|
79 |
|
|
80 |
PipeSign
|
|
81 |
|
|
82 |
^ $>
|
|
83 |
! !
|
|
84 |
|
1086
|
85 |
!Archiver class methodsFor:'queries'!
|
|
86 |
|
|
87 |
canAddFiles
|
|
88 |
|
|
89 |
^ false
|
|
90 |
!
|
|
91 |
|
1106
|
92 |
canDragnDrop
|
|
93 |
|
|
94 |
^ true.
|
|
95 |
!
|
|
96 |
|
1098
|
97 |
canExtractFiles
|
|
98 |
|
|
99 |
^ false
|
|
100 |
!
|
|
101 |
|
1086
|
102 |
canRemoveFiles
|
|
103 |
|
|
104 |
^ false
|
|
105 |
!
|
|
106 |
|
1106
|
107 |
canViewFile
|
|
108 |
|
|
109 |
^ false
|
|
110 |
!
|
|
111 |
|
1086
|
112 |
hasTitleLine
|
|
113 |
|
|
114 |
^ false
|
|
115 |
! !
|
|
116 |
|
1085
|
117 |
!Archiver methodsFor:'accessing'!
|
|
118 |
|
|
119 |
errorStream
|
|
120 |
"return the value of the instance variable 'errorStream' (automatically generated)"
|
|
121 |
|
|
122 |
^ errorStream
|
|
123 |
!
|
|
124 |
|
|
125 |
errorStream:something
|
|
126 |
"set the value of the instance variable 'errorStream' (automatically generated)"
|
|
127 |
|
|
128 |
errorStream := something.
|
|
129 |
!
|
|
130 |
|
|
131 |
fileName
|
|
132 |
"return the value of the instance variable 'fileName' (automatically generated)"
|
|
133 |
|
|
134 |
^ fileName
|
|
135 |
!
|
|
136 |
|
|
137 |
fileName:something
|
|
138 |
"set the value of the instance variable 'fileName' (automatically generated)"
|
|
139 |
|
|
140 |
fileName := something.
|
|
141 |
!
|
|
142 |
|
|
143 |
outStream
|
|
144 |
"return the value of the instance variable 'outStream' (automatically generated)"
|
|
145 |
|
|
146 |
^ outStream
|
|
147 |
!
|
|
148 |
|
|
149 |
outStream:something
|
|
150 |
"set the value of the instance variable 'outStream' (automatically generated)"
|
|
151 |
|
|
152 |
outStream := something.
|
|
153 |
!
|
|
154 |
|
|
155 |
process
|
|
156 |
"return the value of the instance variable 'process' (automatically generated)"
|
|
157 |
|
|
158 |
^ process
|
|
159 |
!
|
|
160 |
|
|
161 |
process:something
|
|
162 |
"set the value of the instance variable 'process' (automatically generated)"
|
|
163 |
|
|
164 |
process := something.
|
|
165 |
!
|
|
166 |
|
|
167 |
synchron
|
|
168 |
"return the value of the instance variable 'synchron' (automatically generated)"
|
|
169 |
|
|
170 |
^ synchron
|
|
171 |
!
|
|
172 |
|
|
173 |
synchron:something
|
|
174 |
"set the value of the instance variable 'synchron' (automatically generated)"
|
|
175 |
|
|
176 |
synchron := something.
|
|
177 |
!
|
|
178 |
|
|
179 |
temporaryDirectory
|
|
180 |
"return the value of the instance variable 'temporaryDirectory' (automatically generated)"
|
|
181 |
|
|
182 |
temporaryDirectory isNil ifTrue:[
|
|
183 |
temporaryDirectory := Filename newTemporary.
|
|
184 |
temporaryDirectory makeDirectory.
|
|
185 |
].
|
|
186 |
^ temporaryDirectory
|
|
187 |
! !
|
|
188 |
|
|
189 |
!Archiver methodsFor:'actions'!
|
|
190 |
|
|
191 |
addFilesToArchiv:colOfFiles
|
|
192 |
|
|
193 |
self subclassResponsibility.
|
|
194 |
!
|
|
195 |
|
|
196 |
extractTo:aColOfFiles
|
|
197 |
|
|
198 |
self subclassResponsibility.
|
|
199 |
!
|
|
200 |
|
|
201 |
listFilesFromArchiv
|
|
202 |
|
|
203 |
self subclassResponsibility.
|
|
204 |
!
|
|
205 |
|
|
206 |
removeFilesFromArchiv:aColOfFiles
|
|
207 |
|
|
208 |
self subclassResponsibility.
|
|
209 |
! !
|
|
210 |
|
|
211 |
!Archiver methodsFor:'actions private'!
|
|
212 |
|
|
213 |
removeTemporaryDirectory
|
|
214 |
|
|
215 |
| tmp |
|
|
216 |
|
|
217 |
temporaryDirectory notNil ifTrue:[
|
|
218 |
tmp := self temporaryDirectory.
|
|
219 |
(FileDirectory directoryNamed:(tmp directory)) removeDirectory:tmp baseName.
|
|
220 |
temporaryDirectory := nil.
|
|
221 |
].
|
|
222 |
!
|
|
223 |
|
|
224 |
stopProcess
|
|
225 |
|
|
226 |
process notNil ifTrue:[
|
|
227 |
process terminateWithAllSubprocesses.
|
|
228 |
process waitUntilTerminated.
|
|
229 |
].
|
|
230 |
! !
|
|
231 |
|
|
232 |
!Archiver methodsFor:'command execution'!
|
|
233 |
|
|
234 |
executeCommand:cmd directory:aDirectory
|
|
235 |
|
|
236 |
|
|
237 |
synchron isNil ifTrue:[synchron := true].
|
|
238 |
synchron ifTrue:[
|
|
239 |
OperatingSystem
|
|
240 |
executeCommand:cmd
|
|
241 |
inputFrom:nil
|
|
242 |
outputTo:outStream
|
|
243 |
errorTo:errorStream
|
|
244 |
inDirectory:aDirectory
|
|
245 |
lineWise:true
|
|
246 |
onError:[:status| false].
|
|
247 |
] ifFalse:[
|
|
248 |
process := Process for:[
|
|
249 |
[
|
|
250 |
OperatingSystem
|
|
251 |
executeCommand:cmd
|
|
252 |
inputFrom:nil
|
|
253 |
outputTo:outStream
|
|
254 |
errorTo:errorStream
|
|
255 |
inDirectory:aDirectory
|
|
256 |
lineWise:true
|
|
257 |
onError:[:status| false].
|
|
258 |
]
|
|
259 |
valueNowOrOnUnwindDo:[
|
|
260 |
process := nil.
|
|
261 |
].
|
|
262 |
|
|
263 |
] priority:(Processor systemBackgroundPriority).
|
|
264 |
process name:('ArchivFileCommand command >', cmd).
|
|
265 |
process resume.
|
|
266 |
]
|
|
267 |
!
|
|
268 |
|
|
269 |
outStream:aOutStream errorStream:aErrorStream
|
|
270 |
|
|
271 |
outStream := aOutStream.
|
|
272 |
errorStream := aErrorStream.
|
|
273 |
!
|
|
274 |
|
|
275 |
outStream:aOutStream errorStream:aErrorStream synchron:aBoolean
|
|
276 |
|
|
277 |
outStream := aOutStream.
|
|
278 |
errorStream := aErrorStream.
|
|
279 |
synchron := aBoolean
|
|
280 |
! !
|
|
281 |
|
|
282 |
!Archiver methodsFor:'initialization & release'!
|
|
283 |
|
|
284 |
release
|
|
285 |
|
|
286 |
self stopProcess.
|
|
287 |
self removeTemporaryDirectory.
|
|
288 |
! !
|
|
289 |
|
1086
|
290 |
!Archiver::GZipArchive class methodsFor:'columns'!
|
|
291 |
|
|
292 |
columns
|
|
293 |
|
|
294 |
"/ columns in stream order
|
|
295 |
"/ colums id words to read
|
|
296 |
^ #( #(#method 1)
|
|
297 |
#(#crc 1)
|
|
298 |
#(#dateAndTime 3)
|
|
299 |
#(#compressSize 1)
|
|
300 |
#(#size 1)
|
|
301 |
#(#ratio 1)
|
|
302 |
#(#fileName 1)
|
|
303 |
)
|
|
304 |
! !
|
|
305 |
|
|
306 |
!Archiver::GZipArchive class methodsFor:'queries'!
|
|
307 |
|
1106
|
308 |
canViewFile
|
|
309 |
|
|
310 |
^ true
|
|
311 |
!
|
|
312 |
|
1086
|
313 |
hasTitleLine
|
|
314 |
|
|
315 |
^ true
|
|
316 |
! !
|
|
317 |
|
1085
|
318 |
!Archiver::GZipArchive class methodsFor:'zip archiv command options'!
|
|
319 |
|
|
320 |
GZipArchivFileOption
|
|
321 |
^ 'f'
|
|
322 |
!
|
|
323 |
|
|
324 |
GZipArchivUnzipCommand
|
|
325 |
^ 'gunzip'
|
|
326 |
!
|
|
327 |
|
|
328 |
GZipArchivWriteToStdioOption
|
|
329 |
^ 'c'
|
|
330 |
!
|
|
331 |
|
|
332 |
GZipArchivZipCommand
|
|
333 |
^ 'gzip'
|
1086
|
334 |
!
|
|
335 |
|
|
336 |
GZipArchivZipListOption
|
|
337 |
^ $l
|
|
338 |
!
|
|
339 |
|
|
340 |
GZipArchivZipQuietOption
|
|
341 |
^ $q
|
|
342 |
!
|
|
343 |
|
|
344 |
GZipArchivZipVerboseOption
|
|
345 |
^ $v
|
1085
|
346 |
! !
|
|
347 |
|
|
348 |
!Archiver::GZipArchive methodsFor:'actions'!
|
|
349 |
|
1106
|
350 |
extractTo:aDirectory
|
|
351 |
|
|
352 |
self unzipTo:aDirectory
|
|
353 |
!
|
|
354 |
|
|
355 |
extractTo:aDirectory with:extractFiles
|
|
356 |
|
|
357 |
self unzipTo:aDirectory
|
|
358 |
!
|
|
359 |
|
1086
|
360 |
listFilesFromArchiv
|
|
361 |
|
|
362 |
| cmd dir|
|
|
363 |
|
|
364 |
self fileName isNil ifTrue:[ ^ self].
|
|
365 |
dir := self fileName directory.
|
|
366 |
cmd := self getFileListFromArchivCommand.
|
|
367 |
self executeCommand:cmd directory:dir
|
|
368 |
!
|
|
369 |
|
|
370 |
listFilesFromArchiv:aCol
|
|
371 |
|
|
372 |
self listFilesFromArchiv
|
|
373 |
!
|
|
374 |
|
1085
|
375 |
unzipTo:aDirectory
|
|
376 |
|
|
377 |
| cmd file newFile|
|
|
378 |
|
|
379 |
(aDirectory exists not) ifTrue:[
|
|
380 |
DialogBox warn:'cant unzip to not existing directory ', aDirectory asString.
|
|
381 |
].
|
|
382 |
(aDirectory isDirectory not) ifTrue:[
|
|
383 |
DialogBox warn:'cant unzip to file ', aDirectory asString.
|
|
384 |
].
|
|
385 |
file := self fileName.
|
|
386 |
(file directory asString = aDirectory asString) ifFalse:[
|
|
387 |
file copyTo:(aDirectory construct:(file baseName)).
|
|
388 |
].
|
|
389 |
newFile := aDirectory construct:(file baseName).
|
|
390 |
cmd := self getUnzipCommandForFile:newFile.
|
|
391 |
self executeCommand:cmd directory:aDirectory.
|
|
392 |
!
|
|
393 |
|
|
394 |
zipFile:aFile to:newFile
|
|
395 |
|
|
396 |
| cmd directory|
|
|
397 |
|
|
398 |
directory := newFile directory.
|
|
399 |
(directory exists not) ifTrue:[
|
|
400 |
DialogBox warn:'cant unzip to not existing directory ', directory asString.
|
|
401 |
].
|
|
402 |
(directory isDirectory not) ifTrue:[
|
|
403 |
DialogBox warn:'cant unzip to file ', directory asString.
|
|
404 |
].
|
|
405 |
cmd := self getZipCommandForFile:aFile to:newFile.
|
|
406 |
self executeCommand:cmd directory:directory.
|
|
407 |
newFile exists ifTrue:[
|
|
408 |
self fileName:newFile.
|
|
409 |
].
|
|
410 |
! !
|
|
411 |
|
|
412 |
!Archiver::GZipArchive methodsFor:'command strings'!
|
|
413 |
|
1086
|
414 |
getFileListFromArchivCommand
|
|
415 |
|
|
416 |
| stream cmd|
|
|
417 |
|
|
418 |
stream := WriteStream on:''.
|
|
419 |
stream nextPutAll:self class GZipArchivZipCommand.
|
|
420 |
stream space.
|
|
421 |
stream nextPut:self class MinusSign.
|
|
422 |
stream nextPut:self class GZipArchivZipListOption.
|
|
423 |
stream space.
|
|
424 |
stream nextPut:self class MinusSign.
|
|
425 |
stream nextPut:self class GZipArchivZipVerboseOption.
|
|
426 |
stream space.
|
|
427 |
stream nextPutAll:self fileName baseName.
|
|
428 |
cmd := stream contents.
|
|
429 |
stream close.
|
|
430 |
^ cmd
|
|
431 |
!
|
|
432 |
|
1085
|
433 |
getUnzipCommand
|
|
434 |
|
|
435 |
| stream cmd|
|
|
436 |
|
|
437 |
stream := WriteStream on:''.
|
|
438 |
stream nextPutAll:self class GZipArchivUnzipCommand.
|
|
439 |
stream space.
|
|
440 |
stream nextPutAll:self fileName baseName.
|
|
441 |
cmd := stream contents.
|
|
442 |
stream close.
|
|
443 |
^ cmd
|
|
444 |
!
|
|
445 |
|
|
446 |
getUnzipCommandForFile:aFileName
|
|
447 |
|
|
448 |
| stream cmd|
|
|
449 |
|
|
450 |
stream := WriteStream on:''.
|
|
451 |
stream nextPutAll:self class GZipArchivUnzipCommand.
|
|
452 |
stream space.
|
|
453 |
stream nextPutAll:aFileName asString.
|
|
454 |
cmd := stream contents.
|
|
455 |
stream close.
|
|
456 |
^ cmd
|
|
457 |
!
|
|
458 |
|
|
459 |
getZipCommandForFile:aFileName
|
|
460 |
|
|
461 |
| stream cmd|
|
|
462 |
|
|
463 |
stream := WriteStream on:''.
|
|
464 |
stream nextPutAll:self class GZipArchivZipCommand.
|
|
465 |
stream space.
|
|
466 |
stream nextPutAll:aFileName asString.
|
|
467 |
cmd := stream contents.
|
|
468 |
stream close.
|
|
469 |
^ cmd
|
|
470 |
!
|
|
471 |
|
|
472 |
getZipCommandForFile:aFile to:newFile
|
|
473 |
| stream cmd|
|
|
474 |
|
|
475 |
stream := WriteStream on:''.
|
|
476 |
stream nextPutAll:self class GZipArchivZipCommand.
|
|
477 |
stream space.
|
|
478 |
stream nextPut:self class MinusSign.
|
|
479 |
stream nextPutAll:self class GZipArchivWriteToStdioOption.
|
|
480 |
stream space.
|
|
481 |
stream nextPutAll:aFile asString.
|
|
482 |
stream space.
|
|
483 |
stream nextPut:self class PipeSign.
|
|
484 |
stream space.
|
|
485 |
stream nextPutAll:newFile asString.
|
|
486 |
cmd := stream contents.
|
|
487 |
stream close.
|
|
488 |
^ cmd
|
|
489 |
! !
|
|
490 |
|
1086
|
491 |
!Archiver::TarArchive class methodsFor:'columns'!
|
|
492 |
|
|
493 |
columns
|
|
494 |
|
|
495 |
"/ colums id words to read
|
|
496 |
^ #( #(#permissions 1)
|
|
497 |
#(#ownerGroup 1)
|
|
498 |
#(#size 1)
|
|
499 |
#(#dateAndTime 2)
|
|
500 |
#(#fileName 1)
|
|
501 |
)
|
|
502 |
! !
|
|
503 |
|
1085
|
504 |
!Archiver::TarArchive class methodsFor:'command strings'!
|
|
505 |
|
|
506 |
TarArchivAddOption
|
|
507 |
^ 'r'
|
|
508 |
!
|
|
509 |
|
|
510 |
TarArchivCommand
|
|
511 |
^ 'tar'
|
|
512 |
!
|
|
513 |
|
|
514 |
TarArchivDeleteOption
|
|
515 |
^ '--delete'
|
|
516 |
!
|
|
517 |
|
|
518 |
TarArchivFileOption
|
|
519 |
^ 'f'
|
|
520 |
!
|
|
521 |
|
|
522 |
TarArchivListContentsOption
|
|
523 |
^ 't'
|
|
524 |
!
|
|
525 |
|
|
526 |
TarArchivListOptions
|
|
527 |
^ self TarArchivListContentsOption , self TarArchivVerboseOption
|
|
528 |
, self TarArchivFileOption
|
|
529 |
!
|
|
530 |
|
|
531 |
TarArchivListZippedOptions
|
|
532 |
^ self TarArchivListContentsOption , self TarArchivVerboseOption
|
|
533 |
, self TarArchivFileOption , self TarArchivZipOption
|
|
534 |
!
|
|
535 |
|
|
536 |
TarArchivUnpackInDirectoryOption
|
|
537 |
^ '-C '
|
|
538 |
!
|
|
539 |
|
|
540 |
TarArchivUnpackOption
|
|
541 |
^ 'x'
|
|
542 |
!
|
|
543 |
|
|
544 |
TarArchivVerboseOption
|
|
545 |
^ 'v'
|
|
546 |
!
|
|
547 |
|
|
548 |
TarArchivZipOption
|
|
549 |
^ 'z'
|
|
550 |
! !
|
|
551 |
|
1086
|
552 |
!Archiver::TarArchive class methodsFor:'queries'!
|
|
553 |
|
|
554 |
canAddFiles
|
|
555 |
|
|
556 |
^ true
|
|
557 |
!
|
|
558 |
|
|
559 |
canRemoveFiles
|
|
560 |
|
|
561 |
^ true
|
1106
|
562 |
!
|
|
563 |
|
|
564 |
canViewFile
|
|
565 |
|
|
566 |
^ true
|
1086
|
567 |
! !
|
|
568 |
|
1085
|
569 |
!Archiver::TarArchive methodsFor:'actions'!
|
|
570 |
|
|
571 |
addFilesToArchiv:colOfFiles
|
|
572 |
|
|
573 |
| cmd tempDir archivFile archivInTemp|
|
|
574 |
|
|
575 |
tempDir := self temporaryDirectory.
|
|
576 |
archivFile := self fileName.
|
|
577 |
archivInTemp := tempDir construct:(archivFile baseName).
|
|
578 |
"/ copy files to be added to tempDir
|
|
579 |
colOfFiles do:[ :file |
|
1088
|
580 |
file recursiveCopyTo:(tempDir construct:(file asFilename baseName))
|
1085
|
581 |
].
|
|
582 |
|
|
583 |
"/ copy tar archiv to tempDir
|
|
584 |
archivFile copyTo:archivInTemp.
|
|
585 |
|
|
586 |
"/ addFiles to the tar archive
|
|
587 |
cmd := self getAddFilesToTarArchiveCommandForArchiv:archivInTemp with:colOfFiles.
|
|
588 |
self executeCommand:cmd directory:tempDir.
|
|
589 |
|
|
590 |
"/ copy tar archiv back
|
|
591 |
archivInTemp copyTo:(self fileName).
|
|
592 |
!
|
|
593 |
|
|
594 |
extractTo:aDirectory
|
|
595 |
|
|
596 |
^ self extractTo:aDirectory with:nil
|
|
597 |
!
|
|
598 |
|
|
599 |
extractTo:aDirectory with:files
|
|
600 |
|
|
601 |
|execDir cmd|
|
|
602 |
|
|
603 |
execDir := self fileName directory.
|
|
604 |
cmd := self getExtractSelectedFilesCommandForDirectory:aDirectory withSelection:files.
|
|
605 |
self executeCommand:cmd directory:execDir.
|
|
606 |
!
|
|
607 |
|
|
608 |
extractWithOutDirectoryTo:aDirectory with:files
|
|
609 |
|
|
610 |
|execDir tempDir tempFile|
|
|
611 |
|
|
612 |
execDir := self fileName directory.
|
|
613 |
tempDir := self temporaryDirectory.
|
|
614 |
self extractTo:tempDir with:files.
|
|
615 |
files do:[ : aFileString |
|
|
616 |
tempFile := self temporaryDirectory construct:aFileString.
|
|
617 |
tempFile exists ifTrue:[
|
|
618 |
tempFile recursiveCopyTo:(aDirectory construct:(aFileString fileName asFilename baseName)).
|
|
619 |
].
|
|
620 |
].
|
|
621 |
!
|
|
622 |
|
|
623 |
listFilesFromArchiv
|
|
624 |
|
|
625 |
self listFilesFromArchiv:nil
|
|
626 |
!
|
|
627 |
|
|
628 |
listFilesFromArchiv:newColOfFiles
|
|
629 |
|
|
630 |
| cmd dir|
|
|
631 |
|
|
632 |
self fileName isNil ifTrue:[ ^ self].
|
|
633 |
dir := self fileName directory.
|
|
634 |
cmd := self getFileListFromArchivCommand:newColOfFiles.
|
|
635 |
self executeCommand:cmd directory:dir
|
|
636 |
!
|
|
637 |
|
|
638 |
removeFilesFromArchiv:aColOfFiles
|
|
639 |
|
|
640 |
|cmd|
|
|
641 |
|
|
642 |
cmd := self getRemoveFilesFromTarArchivFor:aColOfFiles.
|
|
643 |
self executeCommand:cmd directory:(self fileName directory).
|
|
644 |
! !
|
|
645 |
|
|
646 |
!Archiver::TarArchive methodsFor:'command strings'!
|
|
647 |
|
|
648 |
getAddFilesToTarArchiveCommandForArchiv:archivFile with:aColOfFiles
|
|
649 |
| cmd stream|
|
|
650 |
|
|
651 |
archivFile exists ifTrue:[
|
|
652 |
stream := WriteStream on:''.
|
|
653 |
stream nextPutAll:self class TarArchivCommand.
|
|
654 |
stream space.
|
|
655 |
stream nextPutAll:self class TarArchivAddOption.
|
|
656 |
stream nextPutAll:self class TarArchivFileOption.
|
|
657 |
stream space.
|
|
658 |
stream nextPutAll:archivFile asString.
|
|
659 |
aColOfFiles do:[:el |
|
|
660 |
stream space.
|
1088
|
661 |
stream nextPutAll:(el asFilename baseName)
|
1085
|
662 |
].
|
|
663 |
cmd := stream contents
|
|
664 |
].
|
|
665 |
^ cmd
|
|
666 |
!
|
|
667 |
|
|
668 |
getExtractSelectedFilesCommandForDirectory:dir withSelection:sel
|
|
669 |
| stream cmd|
|
|
670 |
|
|
671 |
stream := WriteStream on:''.
|
|
672 |
stream nextPutAll:self class TarArchivCommand.
|
|
673 |
stream space.
|
|
674 |
stream nextPutAll:self class TarArchivUnpackOption.
|
|
675 |
stream nextPutAll:self class TarArchivFileOption.
|
|
676 |
stream space.
|
|
677 |
stream nextPutAll:self fileName asString.
|
|
678 |
stream space.
|
|
679 |
stream nextPutAll:self class TarArchivUnpackInDirectoryOption.
|
|
680 |
stream space.
|
|
681 |
stream nextPutAll:dir asString.
|
|
682 |
sel notNil ifTrue:[
|
|
683 |
sel do:[:el |
|
|
684 |
stream space.
|
1088
|
685 |
stream nextPutAll:(el asString)
|
1085
|
686 |
].
|
|
687 |
].
|
|
688 |
cmd := stream contents.
|
|
689 |
stream close.
|
|
690 |
^ cmd
|
|
691 |
!
|
|
692 |
|
|
693 |
getFileListFromArchivCommand:aColOfFiles
|
|
694 |
|
|
695 |
| stream cmd|
|
|
696 |
|
|
697 |
stream := WriteStream on:''.
|
|
698 |
stream nextPutAll:self class TarArchivCommand.
|
|
699 |
stream space.
|
|
700 |
stream nextPutAll:self class TarArchivListOptions.
|
|
701 |
stream space.
|
|
702 |
stream nextPutAll:self fileName baseName.
|
|
703 |
aColOfFiles notNil ifTrue:[
|
|
704 |
aColOfFiles do:[:el |
|
|
705 |
stream space.
|
|
706 |
stream nextPutAll:(el baseName)
|
|
707 |
]
|
|
708 |
].
|
|
709 |
cmd := stream contents.
|
|
710 |
stream close.
|
|
711 |
^ cmd
|
|
712 |
!
|
|
713 |
|
|
714 |
getRemoveFilesFromTarArchivFor:sel
|
|
715 |
| stream filename|
|
|
716 |
|
|
717 |
filename := self fileName.
|
|
718 |
filename exists ifTrue:[
|
|
719 |
stream := WriteStream on:''.
|
|
720 |
stream nextPutAll:self class TarArchivCommand.
|
|
721 |
stream space.
|
|
722 |
stream nextPutAll:self class TarArchivDeleteOption.
|
|
723 |
stream space.
|
|
724 |
stream nextPut:self class MinusSign.
|
|
725 |
stream nextPutAll:self class TarArchivFileOption.
|
|
726 |
stream space.
|
|
727 |
stream nextPutAll:filename asString.
|
|
728 |
sel do:[:el |
|
|
729 |
stream space.
|
|
730 |
stream nextPutAll:el
|
|
731 |
].
|
|
732 |
^ stream contents
|
|
733 |
]
|
|
734 |
! !
|
|
735 |
|
1086
|
736 |
!Archiver::TarGZipArchive class methodsFor:'columns'!
|
|
737 |
|
|
738 |
columns
|
|
739 |
|
|
740 |
^ Archiver tarArchive columns
|
|
741 |
! !
|
|
742 |
|
|
743 |
!Archiver::TarGZipArchive class methodsFor:'queries'!
|
|
744 |
|
|
745 |
canAddFiles
|
|
746 |
|
|
747 |
^ Archiver tarArchive canAddFiles
|
|
748 |
!
|
|
749 |
|
|
750 |
canRemoveFiles
|
|
751 |
|
|
752 |
^ Archiver tarArchive canRemoveFiles
|
1106
|
753 |
!
|
|
754 |
|
|
755 |
canViewFile
|
|
756 |
|
|
757 |
^ Archiver tarArchive canViewFile
|
1086
|
758 |
! !
|
|
759 |
|
1085
|
760 |
!Archiver::TarGZipArchive methodsFor:'accessing'!
|
|
761 |
|
|
762 |
fileName:aFile
|
|
763 |
|
|
764 |
| tempDir file gzipArchiver suffix|
|
|
765 |
|
|
766 |
super fileName:aFile.
|
|
767 |
" unzip file in tempDirectory and do all the things with tar file "
|
|
768 |
tempDir := self temporaryDirectory.
|
|
769 |
gzipArchiver := Archiver::GZipArchive with:(self fileName).
|
|
770 |
gzipArchiver unzipTo:tempDir.
|
|
771 |
suffix := self fileName suffix.
|
|
772 |
file := self fileName withoutSuffix.
|
|
773 |
file := file baseName.
|
|
774 |
suffix = 'tgz' ifTrue:[
|
|
775 |
file := file , '.tar'
|
|
776 |
].
|
|
777 |
tarFile := self temporaryDirectory construct:file.
|
1088
|
778 |
tarArchiver := Archiver tarArchive with:tarFile.
|
1085
|
779 |
! !
|
|
780 |
|
|
781 |
!Archiver::TarGZipArchive methodsFor:'actions'!
|
|
782 |
|
|
783 |
addFilesToArchiv:colOfFiles
|
|
784 |
|
|
785 |
self setCommandOptions.
|
|
786 |
tarArchiver addFilesToArchiv:colOfFiles.
|
1098
|
787 |
"/ synchronize the tar archive under temporary file with archiv file position
|
1085
|
788 |
self synchronize.
|
|
789 |
!
|
|
790 |
|
|
791 |
extractTo:aDirectory
|
|
792 |
|
|
793 |
self extractTo:aDirectory with:nil.
|
|
794 |
!
|
|
795 |
|
|
796 |
extractTo:aDirectory with:col
|
|
797 |
|
|
798 |
self setCommandOptions.
|
|
799 |
tarArchiver extractTo:aDirectory with:col.
|
|
800 |
!
|
|
801 |
|
|
802 |
extractWithOutDirectoryTo:aDirectory with:files
|
|
803 |
|
|
804 |
self setCommandOptions.
|
|
805 |
tarArchiver extractWithOutDirectoryTo:aDirectory with:files.
|
|
806 |
!
|
|
807 |
|
|
808 |
listFilesFromArchiv
|
|
809 |
|
|
810 |
self listFilesFromArchiv:nil
|
|
811 |
!
|
|
812 |
|
|
813 |
listFilesFromArchiv:newColOfFiles
|
|
814 |
|
|
815 |
self setCommandOptions.
|
|
816 |
^ tarArchiver listFilesFromArchiv:newColOfFiles.
|
|
817 |
!
|
|
818 |
|
|
819 |
removeFilesFromArchiv:aColOfFiles
|
|
820 |
|
|
821 |
self setCommandOptions.
|
|
822 |
tarArchiver removeFilesFromArchiv:aColOfFiles.
|
|
823 |
self synchronize.
|
|
824 |
! !
|
|
825 |
|
|
826 |
!Archiver::TarGZipArchive methodsFor:'actions private'!
|
|
827 |
|
|
828 |
setCommandOptions
|
|
829 |
|
|
830 |
tarArchiver outStream:(self outStream).
|
|
831 |
tarArchiver errorStream:(self errorStream).
|
|
832 |
tarArchiver synchron:(self synchron).
|
|
833 |
!
|
|
834 |
|
|
835 |
synchronize
|
|
836 |
|
|
837 |
|gzipArchiver|
|
|
838 |
|
|
839 |
gzipArchiver := GZipArchive with:nil.
|
|
840 |
gzipArchiver zipFile:(tarArchiver fileName) to:(self fileName).
|
|
841 |
! !
|
|
842 |
|
|
843 |
!Archiver::TarGZipArchive methodsFor:'initialization & release'!
|
|
844 |
|
|
845 |
release
|
|
846 |
|
|
847 |
super release.
|
|
848 |
tarArchiver release.
|
|
849 |
! !
|
|
850 |
|
1086
|
851 |
!Archiver::ZipArchive class methodsFor:'columns'!
|
|
852 |
|
|
853 |
columns
|
|
854 |
|
|
855 |
"/ colums id words to read
|
|
856 |
^ #( #(#permissions 1)
|
|
857 |
#(#version 2)
|
|
858 |
#(#size 1)
|
|
859 |
#(#type 1)
|
|
860 |
#(#ratio 1)
|
|
861 |
#(#dateAndTime 2)
|
|
862 |
#(#fileName 1)
|
|
863 |
)
|
|
864 |
! !
|
|
865 |
|
|
866 |
!Archiver::ZipArchive class methodsFor:'command strings'!
|
|
867 |
|
1088
|
868 |
UnzipExtDirectoryOption
|
|
869 |
^ $d
|
|
870 |
!
|
|
871 |
|
|
872 |
UnzipOverwriteExistingFilesOption
|
|
873 |
^ $o
|
|
874 |
!
|
|
875 |
|
1086
|
876 |
ZipArchivCommand
|
|
877 |
^ 'zip'
|
|
878 |
!
|
|
879 |
|
1088
|
880 |
ZipDeleteOption
|
|
881 |
^ $d
|
|
882 |
!
|
|
883 |
|
1087
|
884 |
ZipHeaderOption
|
|
885 |
^ $h
|
|
886 |
!
|
|
887 |
|
1086
|
888 |
ZipListCommand
|
|
889 |
^ 'unzip'
|
|
890 |
!
|
|
891 |
|
|
892 |
ZipListOption
|
1087
|
893 |
^ $Z
|
|
894 |
!
|
|
895 |
|
1089
|
896 |
ZipOverwriteExistingFilesOption
|
|
897 |
^ $o
|
|
898 |
!
|
|
899 |
|
1087
|
900 |
ZipRecursiveOption
|
|
901 |
^ $r
|
|
902 |
!
|
|
903 |
|
|
904 |
ZipTotalOption
|
|
905 |
^ $t
|
1086
|
906 |
!
|
|
907 |
|
|
908 |
ZipUnzipCommand
|
|
909 |
^ 'unzip'
|
1087
|
910 |
!
|
|
911 |
|
|
912 |
ZipUnzipExtDirectoryOption
|
|
913 |
^ 'd'
|
1086
|
914 |
! !
|
|
915 |
|
|
916 |
!Archiver::ZipArchive class methodsFor:'queries'!
|
|
917 |
|
|
918 |
canAddFiles
|
|
919 |
|
|
920 |
^ true
|
|
921 |
!
|
|
922 |
|
|
923 |
canRemoveFiles
|
|
924 |
|
|
925 |
^ true
|
1088
|
926 |
!
|
|
927 |
|
|
928 |
hasLastLine
|
|
929 |
|
|
930 |
^ true
|
|
931 |
!
|
|
932 |
|
|
933 |
hasTitleLine
|
|
934 |
|
|
935 |
^ true
|
1086
|
936 |
! !
|
|
937 |
|
|
938 |
!Archiver::ZipArchive methodsFor:'actions'!
|
|
939 |
|
|
940 |
addFilesToArchiv:colOfFiles
|
1087
|
941 |
|
|
942 |
|cmd tempDir archivFile archivInTemp|
|
|
943 |
|
|
944 |
tempDir := self temporaryDirectory.
|
|
945 |
archivFile := self fileName.
|
|
946 |
archivInTemp := tempDir construct:(archivFile baseName).
|
|
947 |
"/ copy files to be added to tempDir
|
|
948 |
colOfFiles do:[ :file |
|
1088
|
949 |
file recursiveCopyTo:(tempDir construct:(file asFilename baseName))
|
1087
|
950 |
].
|
|
951 |
|
|
952 |
"/ copy archiv to tempDir
|
|
953 |
archivFile copyTo:archivInTemp.
|
|
954 |
|
|
955 |
"/ addFiles to the tar archive
|
|
956 |
cmd := self getAddFilesToArchiveCommandForArchiv:archivInTemp with:colOfFiles.
|
1088
|
957 |
self executeCommand:cmd directory:tempDir.
|
1087
|
958 |
|
|
959 |
"/ copy tar archiv back
|
|
960 |
archivInTemp copyTo:(self fileName).
|
1086
|
961 |
!
|
|
962 |
|
|
963 |
extractTo:aDirectory
|
|
964 |
|
|
965 |
^ self extractTo:aDirectory with:nil
|
|
966 |
!
|
|
967 |
|
|
968 |
extractTo:aDirectory with:files
|
1087
|
969 |
|
|
970 |
|execDir cmd|
|
|
971 |
|
|
972 |
execDir := self fileName directory.
|
|
973 |
cmd := self getExtractSelectedFilesCommandForDirectory:aDirectory withSelection:files.
|
|
974 |
self executeCommand:cmd directory:execDir.
|
1086
|
975 |
!
|
|
976 |
|
|
977 |
extractWithOutDirectoryTo:aDirectory with:files
|
1087
|
978 |
|
1088
|
979 |
|execDir tempDir tempFile targetFile|
|
1087
|
980 |
|
|
981 |
execDir := self fileName directory.
|
|
982 |
tempDir := self temporaryDirectory.
|
|
983 |
self extractTo:tempDir with:files.
|
1088
|
984 |
self halt.
|
1087
|
985 |
files do:[ : aFileString |
|
|
986 |
tempFile := self temporaryDirectory construct:aFileString.
|
1088
|
987 |
targetFile := aDirectory construct:(aFileString asFilename baseName).
|
|
988 |
targetFile exists ifTrue:[
|
|
989 |
targetFile recursiveRemove.
|
|
990 |
].
|
1087
|
991 |
tempFile exists ifTrue:[
|
1088
|
992 |
tempFile recursiveCopyTo:targetFile.
|
1087
|
993 |
].
|
|
994 |
].
|
1086
|
995 |
!
|
|
996 |
|
|
997 |
listFilesFromArchiv
|
|
998 |
|
|
999 |
self listFilesFromArchiv:nil
|
|
1000 |
!
|
|
1001 |
|
|
1002 |
listFilesFromArchiv:newColOfFiles
|
|
1003 |
|
|
1004 |
|dir cmd|
|
|
1005 |
|
|
1006 |
self fileName isNil ifTrue:[ ^ self].
|
|
1007 |
dir := self fileName directory.
|
|
1008 |
cmd := self getFileListFromArchivCommand:newColOfFiles.
|
|
1009 |
self executeCommand:cmd directory:dir
|
|
1010 |
!
|
|
1011 |
|
|
1012 |
removeFilesFromArchiv:aColOfFiles
|
1088
|
1013 |
|
|
1014 |
|cmd|
|
|
1015 |
|
|
1016 |
cmd := self getRemoveFilesFromArchivFor:aColOfFiles.
|
|
1017 |
self executeCommand:cmd directory:(self fileName directory).
|
1086
|
1018 |
! !
|
|
1019 |
|
|
1020 |
!Archiver::ZipArchive methodsFor:'command strings'!
|
|
1021 |
|
1087
|
1022 |
getAddFilesToArchiveCommandForArchiv:archivFile with:aColOfFiles
|
1086
|
1023 |
| cmd stream|
|
|
1024 |
|
|
1025 |
archivFile exists ifTrue:[
|
|
1026 |
stream := WriteStream on:''.
|
1087
|
1027 |
stream nextPutAll:self class ZipArchivCommand.
|
1086
|
1028 |
stream space.
|
1087
|
1029 |
stream nextPut:self class MinusSign.
|
|
1030 |
stream nextPut:self class ZipRecursiveOption.
|
1086
|
1031 |
stream space.
|
|
1032 |
stream nextPutAll:archivFile asString.
|
|
1033 |
aColOfFiles do:[:el |
|
|
1034 |
stream space.
|
1088
|
1035 |
stream nextPutAll:(el asFilename baseName)
|
|
1036 |
].
|
|
1037 |
cmd := stream contents
|
|
1038 |
].
|
|
1039 |
^ cmd
|
|
1040 |
!
|
|
1041 |
|
|
1042 |
getAddFilesToTarArchiveCommand:aColOfFiles
|
|
1043 |
|filename cmd stream|
|
|
1044 |
|
|
1045 |
filename := self fileName.
|
|
1046 |
filename exists ifTrue:[
|
|
1047 |
stream := WriteStream on:''.
|
|
1048 |
stream nextPutAll:self class TarArchivCommand.
|
|
1049 |
stream space.
|
|
1050 |
stream nextPutAll:self class TarArchivAddOption.
|
|
1051 |
stream nextPutAll:self class TarArchivFileOption.
|
|
1052 |
stream space.
|
|
1053 |
stream nextPutAll:filename asString.
|
|
1054 |
aColOfFiles do:[:el |
|
|
1055 |
stream space.
|
1086
|
1056 |
stream nextPutAll:(el baseName)
|
|
1057 |
].
|
|
1058 |
cmd := stream contents
|
|
1059 |
].
|
|
1060 |
^ cmd
|
|
1061 |
!
|
|
1062 |
|
1087
|
1063 |
getAddFilesToTarArchiveCommandForArchivFor:aColOfFiles
|
|
1064 |
| cmd stream|
|
|
1065 |
|
|
1066 |
stream := WriteStream on:''.
|
|
1067 |
stream nextPutAll:self class ZipArchivCommand.
|
|
1068 |
stream space.
|
|
1069 |
stream nextPut:self class MinusSign.
|
|
1070 |
stream nextPut:self class ZipRecursiveOption.
|
|
1071 |
stream space.
|
|
1072 |
stream nextPutAll:self fileName asString.
|
|
1073 |
aColOfFiles do:[:el |
|
|
1074 |
stream space.
|
|
1075 |
stream nextPutAll:(el asString)
|
|
1076 |
].
|
|
1077 |
cmd := stream contents.
|
|
1078 |
stream close.
|
|
1079 |
^ cmd
|
|
1080 |
!
|
|
1081 |
|
1086
|
1082 |
getExtractSelectedFilesCommandForDirectory:dir withSelection:sel
|
|
1083 |
| stream cmd|
|
|
1084 |
|
|
1085 |
stream := WriteStream on:''.
|
1087
|
1086 |
stream nextPutAll:self class ZipUnzipCommand.
|
1086
|
1087 |
stream space.
|
1087
|
1088 |
stream nextPut:self class MinusSign.
|
1088
|
1089 |
stream nextPut:self class UnzipOverwriteExistingFilesOption.
|
|
1090 |
stream space.
|
|
1091 |
stream nextPut:self class MinusSign.
|
|
1092 |
stream nextPut:self class UnzipExtDirectoryOption.
|
1087
|
1093 |
stream space.
|
|
1094 |
stream nextPutAll:dir asString.
|
1086
|
1095 |
stream space.
|
|
1096 |
stream nextPutAll:self fileName asString.
|
|
1097 |
sel notNil ifTrue:[
|
|
1098 |
sel do:[:el |
|
|
1099 |
stream space.
|
1088
|
1100 |
stream nextPutAll:(el asString)
|
1086
|
1101 |
].
|
|
1102 |
].
|
|
1103 |
cmd := stream contents.
|
|
1104 |
stream close.
|
|
1105 |
^ cmd
|
|
1106 |
!
|
|
1107 |
|
|
1108 |
getFileListFromArchivCommand:aColOfFiles
|
|
1109 |
|
|
1110 |
| stream cmd|
|
|
1111 |
|
|
1112 |
stream := WriteStream on:''.
|
|
1113 |
stream nextPutAll:self class ZipUnzipCommand.
|
|
1114 |
stream space.
|
|
1115 |
stream nextPut:self class MinusSign.
|
1087
|
1116 |
stream nextPut:self class ZipListOption.
|
1086
|
1117 |
stream space.
|
1087
|
1118 |
stream nextPut:self class MinusSign.
|
|
1119 |
stream nextPut:self class MinusSign.
|
|
1120 |
stream nextPut:self class ZipHeaderOption.
|
|
1121 |
stream nextPut:self class MinusSign.
|
|
1122 |
stream nextPut:self class ZipTotalOption.
|
|
1123 |
stream space.
|
|
1124 |
stream nextPutAll:self fileName asString.
|
1086
|
1125 |
aColOfFiles notNil ifTrue:[
|
|
1126 |
aColOfFiles do:[:el |
|
|
1127 |
stream space.
|
|
1128 |
stream nextPutAll:(el baseName)
|
|
1129 |
]
|
|
1130 |
].
|
|
1131 |
cmd := stream contents.
|
|
1132 |
stream close.
|
|
1133 |
^ cmd
|
|
1134 |
!
|
|
1135 |
|
1087
|
1136 |
getRemoveFilesFromArchivFor:sel
|
1088
|
1137 |
|
|
1138 |
|stream cmd|
|
|
1139 |
|
|
1140 |
stream := WriteStream on:''.
|
|
1141 |
stream nextPutAll:self class ZipArchivCommand.
|
|
1142 |
stream space.
|
|
1143 |
stream nextPut:self class MinusSign.
|
|
1144 |
stream nextPut:self class ZipDeleteOption.
|
|
1145 |
stream space.
|
|
1146 |
stream nextPutAll:self fileName asString.
|
|
1147 |
sel do:[:el |
|
|
1148 |
stream space.
|
|
1149 |
stream nextPutAll:(el asString)
|
|
1150 |
].
|
|
1151 |
cmd := stream contents.
|
|
1152 |
stream close.
|
|
1153 |
^ cmd
|
|
1154 |
!
|
|
1155 |
|
|
1156 |
getRemoveFilesFromTarArchivFor:sel
|
|
1157 |
| stream filename|
|
|
1158 |
|
|
1159 |
filename := self fileName.
|
|
1160 |
filename exists ifTrue:[
|
|
1161 |
stream := WriteStream on:''.
|
|
1162 |
stream nextPutAll:self class TarArchivCommand.
|
|
1163 |
stream space.
|
|
1164 |
stream nextPutAll:self class TarArchivDeleteOption.
|
|
1165 |
stream space.
|
|
1166 |
stream nextPut:self class MinusSign.
|
|
1167 |
stream nextPutAll:self class TarArchivFileOption.
|
|
1168 |
stream space.
|
|
1169 |
stream nextPutAll:filename asString.
|
|
1170 |
sel do:[:el |
|
|
1171 |
stream space.
|
|
1172 |
stream nextPutAll:el
|
|
1173 |
].
|
|
1174 |
^ stream contents
|
|
1175 |
]
|
1086
|
1176 |
! !
|
|
1177 |
|
1085
|
1178 |
!Archiver class methodsFor:'documentation'!
|
|
1179 |
|
|
1180 |
version
|
1106
|
1181 |
^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.7 2002-10-21 14:49:49 penk Exp $'
|
1085
|
1182 |
! !
|