Archiver.st
author Claus Gittinger <cg@exept.de>
Tue, 14 May 2019 09:46:21 +0200
changeset 3663 9d49ecf8661a
parent 1599 629a6e0ae68a
permissions -rw-r--r--
#UI_ENHANCEMENT by cg
class: TabListEditor class
changed:
#canvasSpec
#menu
#windowSpec
penk@1599
     1
"{ Package: 'stx:libtool2' }"
penk@1599
     2
penk@1599
     3
Object subclass:#Archiver
penk@1599
     4
	instanceVariableNames:'process temporaryDirectory fileName outStream errorStream
penk@1599
     5
		synchron'
penk@1599
     6
	classVariableNames:''
penk@1599
     7
	poolDictionaries:''
penk@1599
     8
	category:'System-Support-FileFormats'
penk@1599
     9
!
penk@1599
    10
penk@1599
    11
Archiver subclass:#GZipArchive
penk@1599
    12
	instanceVariableNames:''
penk@1599
    13
	classVariableNames:''
penk@1599
    14
	poolDictionaries:''
penk@1599
    15
	privateIn:Archiver
penk@1599
    16
!
penk@1599
    17
penk@1599
    18
Archiver subclass:#TarArchive
penk@1599
    19
	instanceVariableNames:'fileName'
penk@1599
    20
	classVariableNames:''
penk@1599
    21
	poolDictionaries:''
penk@1599
    22
	privateIn:Archiver
penk@1599
    23
!
penk@1599
    24
penk@1599
    25
Archiver subclass:#TarGZipArchive
penk@1599
    26
	instanceVariableNames:'tarArchiver tarFile'
penk@1599
    27
	classVariableNames:''
penk@1599
    28
	poolDictionaries:''
penk@1599
    29
	privateIn:Archiver
penk@1599
    30
!
penk@1599
    31
penk@1599
    32
penk@1599
    33
!Archiver class methodsFor:'instance creation'!
penk@1599
    34
penk@1599
    35
with:aFilename
penk@1599
    36
penk@1599
    37
    | instance |
penk@1599
    38
penk@1599
    39
    instance := self new.
penk@1599
    40
    instance fileName:aFilename.
penk@1599
    41
    ^ instance
penk@1599
    42
! !
penk@1599
    43
penk@1599
    44
!Archiver class methodsFor:'classAccess'!
penk@1599
    45
penk@1599
    46
gzipArchive
penk@1599
    47
penk@1599
    48
    ^ GZipArchive
penk@1599
    49
!
penk@1599
    50
penk@1599
    51
tarArchive
penk@1599
    52
penk@1599
    53
    ^ TarArchive
penk@1599
    54
!
penk@1599
    55
penk@1599
    56
tarGZipArchive
penk@1599
    57
penk@1599
    58
    ^ TarGZipArchive
penk@1599
    59
! !
penk@1599
    60
penk@1599
    61
!Archiver class methodsFor:'common options'!
penk@1599
    62
penk@1599
    63
MinusSign
penk@1599
    64
penk@1599
    65
    ^ $-
penk@1599
    66
!
penk@1599
    67
penk@1599
    68
PipeSign
penk@1599
    69
penk@1599
    70
    ^ $>
penk@1599
    71
! !
penk@1599
    72
penk@1599
    73
!Archiver methodsFor:'accessing'!
penk@1599
    74
penk@1599
    75
errorStream
penk@1599
    76
    "return the value of the instance variable 'errorStream' (automatically generated)"
penk@1599
    77
penk@1599
    78
    ^ errorStream
penk@1599
    79
!
penk@1599
    80
penk@1599
    81
errorStream:something
penk@1599
    82
    "set the value of the instance variable 'errorStream' (automatically generated)"
penk@1599
    83
penk@1599
    84
    errorStream := something.
penk@1599
    85
!
penk@1599
    86
penk@1599
    87
fileName
penk@1599
    88
    "return the value of the instance variable 'fileName' (automatically generated)"
penk@1599
    89
penk@1599
    90
    ^ fileName
penk@1599
    91
!
penk@1599
    92
penk@1599
    93
fileName:something
penk@1599
    94
    "set the value of the instance variable 'fileName' (automatically generated)"
penk@1599
    95
penk@1599
    96
    fileName := something.
penk@1599
    97
!
penk@1599
    98
penk@1599
    99
outStream
penk@1599
   100
    "return the value of the instance variable 'outStream' (automatically generated)"
penk@1599
   101
penk@1599
   102
    ^ outStream
penk@1599
   103
!
penk@1599
   104
penk@1599
   105
outStream:something
penk@1599
   106
    "set the value of the instance variable 'outStream' (automatically generated)"
penk@1599
   107
penk@1599
   108
    outStream := something.
penk@1599
   109
!
penk@1599
   110
penk@1599
   111
process
penk@1599
   112
    "return the value of the instance variable 'process' (automatically generated)"
penk@1599
   113
penk@1599
   114
    ^ process
penk@1599
   115
!
penk@1599
   116
penk@1599
   117
process:something
penk@1599
   118
    "set the value of the instance variable 'process' (automatically generated)"
penk@1599
   119
penk@1599
   120
    process := something.
penk@1599
   121
!
penk@1599
   122
penk@1599
   123
synchron
penk@1599
   124
    "return the value of the instance variable 'synchron' (automatically generated)"
penk@1599
   125
penk@1599
   126
    ^ synchron
penk@1599
   127
!
penk@1599
   128
penk@1599
   129
synchron:something
penk@1599
   130
    "set the value of the instance variable 'synchron' (automatically generated)"
penk@1599
   131
penk@1599
   132
    synchron := something.
penk@1599
   133
!
penk@1599
   134
penk@1599
   135
temporaryDirectory
penk@1599
   136
    "return the value of the instance variable 'temporaryDirectory' (automatically generated)"
penk@1599
   137
penk@1599
   138
    temporaryDirectory isNil ifTrue:[
penk@1599
   139
        temporaryDirectory := Filename newTemporary.
penk@1599
   140
        temporaryDirectory makeDirectory.
penk@1599
   141
    ].
penk@1599
   142
    ^ temporaryDirectory
penk@1599
   143
! !
penk@1599
   144
penk@1599
   145
!Archiver methodsFor:'actions'!
penk@1599
   146
penk@1599
   147
addFilesToArchiv:colOfFiles
penk@1599
   148
penk@1599
   149
    self subclassResponsibility.
penk@1599
   150
!
penk@1599
   151
penk@1599
   152
extractTo:aColOfFiles
penk@1599
   153
penk@1599
   154
    self subclassResponsibility.
penk@1599
   155
!
penk@1599
   156
penk@1599
   157
listFilesFromArchiv
penk@1599
   158
penk@1599
   159
    self subclassResponsibility.
penk@1599
   160
!
penk@1599
   161
penk@1599
   162
removeFilesFromArchiv:aColOfFiles
penk@1599
   163
penk@1599
   164
    self subclassResponsibility.
penk@1599
   165
! !
penk@1599
   166
penk@1599
   167
!Archiver methodsFor:'actions private'!
penk@1599
   168
penk@1599
   169
removeTemporaryDirectory
penk@1599
   170
penk@1599
   171
    | tmp |
penk@1599
   172
penk@1599
   173
    temporaryDirectory notNil ifTrue:[
penk@1599
   174
        tmp := self temporaryDirectory.
penk@1599
   175
        (FileDirectory directoryNamed:(tmp directory)) removeDirectory:tmp baseName.
penk@1599
   176
        temporaryDirectory := nil.
penk@1599
   177
    ].
penk@1599
   178
!
penk@1599
   179
penk@1599
   180
stopProcess
penk@1599
   181
penk@1599
   182
    process notNil ifTrue:[
penk@1599
   183
        process terminateWithAllSubprocesses.
penk@1599
   184
        process waitUntilTerminated.
penk@1599
   185
    ].
penk@1599
   186
! !
penk@1599
   187
penk@1599
   188
!Archiver methodsFor:'command execution'!
penk@1599
   189
penk@1599
   190
executeCommand:cmd directory:aDirectory
penk@1599
   191
penk@1599
   192
penk@1599
   193
    synchron isNil ifTrue:[synchron := true].
penk@1599
   194
    synchron ifTrue:[
penk@1599
   195
         OperatingSystem 
penk@1599
   196
            executeCommand:cmd
penk@1599
   197
            inputFrom:nil
penk@1599
   198
            outputTo:outStream
penk@1599
   199
            errorTo:errorStream
penk@1599
   200
            inDirectory:aDirectory
penk@1599
   201
            lineWise:true
penk@1599
   202
            onError:[:status| false].
penk@1599
   203
    ] ifFalse:[
penk@1599
   204
        process := Process for:[
penk@1599
   205
                [ 
penk@1599
   206
                     OperatingSystem 
penk@1599
   207
                        executeCommand:cmd
penk@1599
   208
                        inputFrom:nil
penk@1599
   209
                        outputTo:outStream
penk@1599
   210
                        errorTo:errorStream
penk@1599
   211
                        inDirectory:aDirectory
penk@1599
   212
                        lineWise:true
penk@1599
   213
                        onError:[:status| false].
penk@1599
   214
                ] 
penk@1599
   215
                valueNowOrOnUnwindDo:[
penk@1599
   216
                    process := nil.
penk@1599
   217
                ].
penk@1599
   218
penk@1599
   219
        ] priority:(Processor systemBackgroundPriority).
penk@1599
   220
        process name:('ArchivFileCommand command >', cmd).
penk@1599
   221
        process resume.
penk@1599
   222
    ]
penk@1599
   223
!
penk@1599
   224
penk@1599
   225
outStream:aOutStream errorStream:aErrorStream
penk@1599
   226
penk@1599
   227
    outStream := aOutStream.
penk@1599
   228
    errorStream := aErrorStream.
penk@1599
   229
!
penk@1599
   230
penk@1599
   231
outStream:aOutStream errorStream:aErrorStream synchron:aBoolean
penk@1599
   232
penk@1599
   233
    outStream := aOutStream.
penk@1599
   234
    errorStream := aErrorStream.
penk@1599
   235
    synchron := aBoolean
penk@1599
   236
! !
penk@1599
   237
penk@1599
   238
!Archiver methodsFor:'initialization & release'!
penk@1599
   239
penk@1599
   240
release
penk@1599
   241
penk@1599
   242
    self stopProcess.
penk@1599
   243
    self removeTemporaryDirectory.
penk@1599
   244
! !
penk@1599
   245
penk@1599
   246
!Archiver::GZipArchive class methodsFor:'zip archiv command options'!
penk@1599
   247
penk@1599
   248
GZipArchivFileOption
penk@1599
   249
    ^ 'f'
penk@1599
   250
!
penk@1599
   251
penk@1599
   252
GZipArchivUnzipCommand
penk@1599
   253
    ^ 'gunzip'
penk@1599
   254
!
penk@1599
   255
penk@1599
   256
GZipArchivWriteToStdioOption
penk@1599
   257
    ^ 'c'
penk@1599
   258
!
penk@1599
   259
penk@1599
   260
GZipArchivZipCommand
penk@1599
   261
    ^ 'gzip'
penk@1599
   262
! !
penk@1599
   263
penk@1599
   264
!Archiver::GZipArchive methodsFor:'actions'!
penk@1599
   265
penk@1599
   266
unzipTo:aDirectory
penk@1599
   267
penk@1599
   268
    | cmd file newFile|
penk@1599
   269
penk@1599
   270
    (aDirectory exists not) ifTrue:[
penk@1599
   271
        DialogBox warn:'cant unzip to not existing directory ', aDirectory asString.
penk@1599
   272
    ].
penk@1599
   273
    (aDirectory isDirectory not) ifTrue:[
penk@1599
   274
        DialogBox warn:'cant unzip to file ', aDirectory asString.
penk@1599
   275
    ].
penk@1599
   276
    file := self fileName.
penk@1599
   277
    (file directory asString = aDirectory asString) ifFalse:[
penk@1599
   278
        file copyTo:(aDirectory construct:(file baseName)).
penk@1599
   279
    ].
penk@1599
   280
    newFile := aDirectory construct:(file baseName).
penk@1599
   281
    cmd := self getUnzipCommandForFile:newFile.
penk@1599
   282
    self executeCommand:cmd directory:aDirectory. 
penk@1599
   283
!
penk@1599
   284
penk@1599
   285
zipFile:aFile to:newFile
penk@1599
   286
penk@1599
   287
    | cmd directory|
penk@1599
   288
penk@1599
   289
    directory := newFile directory.
penk@1599
   290
    (directory exists not) ifTrue:[
penk@1599
   291
        DialogBox warn:'cant unzip to not existing directory ', directory asString.
penk@1599
   292
    ].
penk@1599
   293
    (directory isDirectory not) ifTrue:[
penk@1599
   294
        DialogBox warn:'cant unzip to file ', directory asString.
penk@1599
   295
    ].
penk@1599
   296
    cmd := self getZipCommandForFile:aFile to:newFile.
penk@1599
   297
    self executeCommand:cmd directory:directory.
penk@1599
   298
    newFile exists ifTrue:[
penk@1599
   299
        self fileName:newFile.
penk@1599
   300
    ].
penk@1599
   301
! !
penk@1599
   302
penk@1599
   303
!Archiver::GZipArchive methodsFor:'command strings'!
penk@1599
   304
penk@1599
   305
getUnzipCommand
penk@1599
   306
penk@1599
   307
    | stream cmd|
penk@1599
   308
penk@1599
   309
    stream := WriteStream on:''.
penk@1599
   310
    stream nextPutAll:self class GZipArchivUnzipCommand.
penk@1599
   311
    stream space.
penk@1599
   312
    stream nextPutAll:self fileName baseName.
penk@1599
   313
    cmd := stream contents.
penk@1599
   314
    stream close.
penk@1599
   315
    ^ cmd
penk@1599
   316
!
penk@1599
   317
penk@1599
   318
getUnzipCommandForFile:aFileName
penk@1599
   319
penk@1599
   320
    | stream cmd|
penk@1599
   321
penk@1599
   322
    stream := WriteStream on:''.
penk@1599
   323
    stream nextPutAll:self class GZipArchivUnzipCommand.
penk@1599
   324
    stream space.
penk@1599
   325
    stream nextPutAll:aFileName asString.
penk@1599
   326
    cmd := stream contents.
penk@1599
   327
    stream close.
penk@1599
   328
    ^ cmd
penk@1599
   329
!
penk@1599
   330
penk@1599
   331
getZipCommandForFile:aFileName
penk@1599
   332
penk@1599
   333
    | stream cmd|
penk@1599
   334
penk@1599
   335
    stream := WriteStream on:''.
penk@1599
   336
    stream nextPutAll:self class GZipArchivZipCommand.
penk@1599
   337
    stream space.
penk@1599
   338
    stream nextPutAll:aFileName asString.
penk@1599
   339
    cmd := stream contents.
penk@1599
   340
    stream close.
penk@1599
   341
    ^ cmd
penk@1599
   342
!
penk@1599
   343
penk@1599
   344
getZipCommandForFile:aFile to:newFile
penk@1599
   345
    | stream cmd|
penk@1599
   346
penk@1599
   347
    stream := WriteStream on:''.
penk@1599
   348
    stream nextPutAll:self class GZipArchivZipCommand.
penk@1599
   349
    stream space.
penk@1599
   350
    stream nextPut:self class MinusSign.
penk@1599
   351
    stream nextPutAll:self class GZipArchivWriteToStdioOption.
penk@1599
   352
    stream space.
penk@1599
   353
    stream nextPutAll:aFile asString.
penk@1599
   354
    stream space.
penk@1599
   355
    stream nextPut:self class PipeSign.
penk@1599
   356
    stream space.
penk@1599
   357
    stream nextPutAll:newFile asString.
penk@1599
   358
    cmd := stream contents.
penk@1599
   359
    stream close.
penk@1599
   360
    ^ cmd
penk@1599
   361
! !
penk@1599
   362
penk@1599
   363
!Archiver::TarArchive class methodsFor:'command strings'!
penk@1599
   364
penk@1599
   365
TarArchivAddOption
penk@1599
   366
    ^ 'r'
penk@1599
   367
!
penk@1599
   368
penk@1599
   369
TarArchivCommand
penk@1599
   370
    ^ 'tar'
penk@1599
   371
!
penk@1599
   372
penk@1599
   373
TarArchivDeleteOption
penk@1599
   374
    ^ '--delete'
penk@1599
   375
!
penk@1599
   376
penk@1599
   377
TarArchivFileOption
penk@1599
   378
    ^ 'f'
penk@1599
   379
!
penk@1599
   380
penk@1599
   381
TarArchivListContentsOption
penk@1599
   382
    ^ 't'
penk@1599
   383
!
penk@1599
   384
penk@1599
   385
TarArchivListOptions
penk@1599
   386
    ^ self TarArchivListContentsOption , self TarArchivVerboseOption 
penk@1599
   387
        , self TarArchivFileOption
penk@1599
   388
!
penk@1599
   389
penk@1599
   390
TarArchivListZippedOptions
penk@1599
   391
    ^ self TarArchivListContentsOption , self TarArchivVerboseOption 
penk@1599
   392
        , self TarArchivFileOption , self TarArchivZipOption
penk@1599
   393
!
penk@1599
   394
penk@1599
   395
TarArchivUnpackInDirectoryOption
penk@1599
   396
    ^ '-C '
penk@1599
   397
!
penk@1599
   398
penk@1599
   399
TarArchivUnpackOption
penk@1599
   400
    ^ 'x'
penk@1599
   401
!
penk@1599
   402
penk@1599
   403
TarArchivVerboseOption
penk@1599
   404
    ^ 'v'
penk@1599
   405
!
penk@1599
   406
penk@1599
   407
TarArchivZipOption
penk@1599
   408
    ^ 'z'
penk@1599
   409
! !
penk@1599
   410
penk@1599
   411
!Archiver::TarArchive methodsFor:'actions'!
penk@1599
   412
penk@1599
   413
addFilesToArchiv:colOfFiles
penk@1599
   414
penk@1599
   415
    | cmd tempDir archivFile archivInTemp|
penk@1599
   416
penk@1599
   417
    tempDir := self temporaryDirectory.
penk@1599
   418
    archivFile := self fileName.
penk@1599
   419
    archivInTemp := tempDir construct:(archivFile baseName).
penk@1599
   420
    "/ copy files to be added to tempDir
penk@1599
   421
    colOfFiles do:[ :file |
penk@1599
   422
        file recursiveCopyTo:(tempDir construct:(file baseName))
penk@1599
   423
    ].
penk@1599
   424
penk@1599
   425
    "/ copy tar archiv to tempDir
penk@1599
   426
    archivFile copyTo:archivInTemp.
penk@1599
   427
penk@1599
   428
    "/ addFiles to the tar archive
penk@1599
   429
    cmd := self getAddFilesToTarArchiveCommandForArchiv:archivInTemp with:colOfFiles.
penk@1599
   430
    self executeCommand:cmd directory:tempDir.
penk@1599
   431
penk@1599
   432
    "/ copy tar archiv back
penk@1599
   433
    archivInTemp copyTo:(self fileName).
penk@1599
   434
!
penk@1599
   435
penk@1599
   436
extractTo:aDirectory 
penk@1599
   437
penk@1599
   438
    ^ self extractTo:aDirectory with:nil
penk@1599
   439
!
penk@1599
   440
penk@1599
   441
extractTo:aDirectory with:files
penk@1599
   442
penk@1599
   443
    |execDir cmd|
penk@1599
   444
penk@1599
   445
    execDir := self fileName directory.
penk@1599
   446
    cmd := self getExtractSelectedFilesCommandForDirectory:aDirectory withSelection:files.
penk@1599
   447
    self executeCommand:cmd directory:execDir.
penk@1599
   448
!
penk@1599
   449
penk@1599
   450
extractWithOutDirectoryTo:aDirectory with:files
penk@1599
   451
penk@1599
   452
    |execDir tempDir tempFile|
penk@1599
   453
penk@1599
   454
    execDir := self fileName directory.
penk@1599
   455
    tempDir := self temporaryDirectory.
penk@1599
   456
    self extractTo:tempDir with:files.
penk@1599
   457
    files do:[ : aFileString |
penk@1599
   458
        tempFile := self temporaryDirectory construct:aFileString.
penk@1599
   459
        tempFile exists ifTrue:[
penk@1599
   460
            tempFile recursiveCopyTo:(aDirectory construct:(aFileString fileName asFilename baseName)).
penk@1599
   461
        ].
penk@1599
   462
    ].
penk@1599
   463
!
penk@1599
   464
penk@1599
   465
listFilesFromArchiv
penk@1599
   466
penk@1599
   467
    self listFilesFromArchiv:nil
penk@1599
   468
!
penk@1599
   469
penk@1599
   470
listFilesFromArchiv:newColOfFiles
penk@1599
   471
penk@1599
   472
    | cmd dir|
penk@1599
   473
penk@1599
   474
    self fileName isNil ifTrue:[ ^ self].
penk@1599
   475
    dir := self fileName directory.
penk@1599
   476
    cmd := self getFileListFromArchivCommand:newColOfFiles.
penk@1599
   477
    self executeCommand:cmd directory:dir 
penk@1599
   478
!
penk@1599
   479
penk@1599
   480
removeFilesFromArchiv:aColOfFiles
penk@1599
   481
penk@1599
   482
    |cmd|
penk@1599
   483
penk@1599
   484
    cmd := self getRemoveFilesFromTarArchivFor:aColOfFiles.
penk@1599
   485
    self executeCommand:cmd directory:(self fileName directory). 
penk@1599
   486
! !
penk@1599
   487
penk@1599
   488
!Archiver::TarArchive methodsFor:'command strings'!
penk@1599
   489
penk@1599
   490
getAddFilesToTarArchiveCommand:aColOfFiles 
penk@1599
   491
    |filename cmd stream|
penk@1599
   492
penk@1599
   493
    filename := self fileName.
penk@1599
   494
    filename exists ifTrue:[
penk@1599
   495
        stream := WriteStream on:''.
penk@1599
   496
        stream nextPutAll:self class TarArchivCommand.
penk@1599
   497
        stream space.
penk@1599
   498
        stream nextPutAll:self class TarArchivAddOption.
penk@1599
   499
        stream nextPutAll:self class TarArchivFileOption.
penk@1599
   500
        stream space.
penk@1599
   501
        stream nextPutAll:filename asString.
penk@1599
   502
        aColOfFiles do:[:el | 
penk@1599
   503
            stream space.
penk@1599
   504
            stream nextPutAll:(el asString)
penk@1599
   505
        ].
penk@1599
   506
        cmd := stream contents
penk@1599
   507
    ].
penk@1599
   508
    ^ cmd
penk@1599
   509
!
penk@1599
   510
penk@1599
   511
getAddFilesToTarArchiveCommandForArchiv:archivFile with:aColOfFiles 
penk@1599
   512
    | cmd stream|
penk@1599
   513
penk@1599
   514
    archivFile exists ifTrue:[
penk@1599
   515
        stream := WriteStream on:''.
penk@1599
   516
        stream nextPutAll:self class TarArchivCommand.
penk@1599
   517
        stream space.
penk@1599
   518
        stream nextPutAll:self class TarArchivAddOption.
penk@1599
   519
        stream nextPutAll:self class TarArchivFileOption.
penk@1599
   520
        stream space.
penk@1599
   521
        stream nextPutAll:archivFile asString.
penk@1599
   522
        aColOfFiles do:[:el | 
penk@1599
   523
            stream space.
penk@1599
   524
            stream nextPutAll:(el baseName)
penk@1599
   525
        ].
penk@1599
   526
        cmd := stream contents
penk@1599
   527
    ].
penk@1599
   528
    ^ cmd
penk@1599
   529
!
penk@1599
   530
penk@1599
   531
getExtractSelectedFilesCommandForDirectory:dir withSelection:sel 
penk@1599
   532
    | stream cmd|
penk@1599
   533
penk@1599
   534
    stream := WriteStream on:''.
penk@1599
   535
    stream nextPutAll:self class TarArchivCommand.
penk@1599
   536
    stream space.
penk@1599
   537
    stream nextPutAll:self class TarArchivUnpackOption.
penk@1599
   538
    stream nextPutAll:self class TarArchivFileOption.
penk@1599
   539
    stream space.
penk@1599
   540
    stream nextPutAll:self fileName asString.
penk@1599
   541
    stream space.
penk@1599
   542
    stream nextPutAll:self class TarArchivUnpackInDirectoryOption.
penk@1599
   543
    stream space.
penk@1599
   544
    stream nextPutAll:dir asString.
penk@1599
   545
    sel notNil ifTrue:[
penk@1599
   546
        sel do:[:el | 
penk@1599
   547
            stream space.
penk@1599
   548
            stream nextPutAll:(el fileName asString)
penk@1599
   549
        ].
penk@1599
   550
    ].
penk@1599
   551
    cmd := stream contents.
penk@1599
   552
    stream close.
penk@1599
   553
    ^ cmd
penk@1599
   554
!
penk@1599
   555
penk@1599
   556
getFileListFromArchivCommand:aColOfFiles 
penk@1599
   557
penk@1599
   558
    | stream cmd|
penk@1599
   559
penk@1599
   560
    stream := WriteStream on:''.
penk@1599
   561
    stream nextPutAll:self class TarArchivCommand.
penk@1599
   562
    stream space.
penk@1599
   563
    stream nextPutAll:self class TarArchivListOptions.
penk@1599
   564
    stream space.
penk@1599
   565
    stream nextPutAll:self fileName baseName.
penk@1599
   566
    aColOfFiles notNil ifTrue:[
penk@1599
   567
        aColOfFiles do:[:el | 
penk@1599
   568
            stream space.
penk@1599
   569
            stream nextPutAll:(el baseName)
penk@1599
   570
        ]
penk@1599
   571
    ].
penk@1599
   572
    cmd := stream contents.
penk@1599
   573
    stream close.
penk@1599
   574
    ^ cmd
penk@1599
   575
!
penk@1599
   576
penk@1599
   577
getRemoveFilesFromTarArchivFor:sel 
penk@1599
   578
    | stream filename|
penk@1599
   579
penk@1599
   580
    filename := self fileName.
penk@1599
   581
    filename exists ifTrue:[
penk@1599
   582
        stream := WriteStream on:''.
penk@1599
   583
        stream nextPutAll:self class TarArchivCommand.
penk@1599
   584
        stream space.
penk@1599
   585
        stream nextPutAll:self class TarArchivDeleteOption.
penk@1599
   586
        stream space.
penk@1599
   587
        stream nextPut:self class MinusSign.
penk@1599
   588
        stream nextPutAll:self class TarArchivFileOption.
penk@1599
   589
        stream space.
penk@1599
   590
        stream nextPutAll:filename asString.
penk@1599
   591
        sel do:[:el | 
penk@1599
   592
            stream space.
penk@1599
   593
            stream nextPutAll:el
penk@1599
   594
        ].
penk@1599
   595
        ^ stream contents
penk@1599
   596
    ]
penk@1599
   597
! !
penk@1599
   598
penk@1599
   599
!Archiver::TarGZipArchive methodsFor:'accessing'!
penk@1599
   600
penk@1599
   601
fileName:aFile
penk@1599
   602
penk@1599
   603
    | tempDir file gzipArchiver suffix|
penk@1599
   604
penk@1599
   605
    super fileName:aFile.
penk@1599
   606
    " unzip file in tempDirectory and do all the things with tar file "
penk@1599
   607
    tempDir := self temporaryDirectory.
penk@1599
   608
    gzipArchiver := Archiver::GZipArchive with:(self fileName).
penk@1599
   609
    gzipArchiver unzipTo:tempDir.
penk@1599
   610
    suffix := self fileName suffix.
penk@1599
   611
    file := self fileName withoutSuffix.
penk@1599
   612
    file := file baseName.
penk@1599
   613
    suffix = 'tgz' ifTrue:[
penk@1599
   614
        file := file , '.tar'
penk@1599
   615
    ].
penk@1599
   616
    tarFile := self temporaryDirectory construct:file.
penk@1599
   617
    tarArchiver := TarArchive with:tarFile.
penk@1599
   618
! !
penk@1599
   619
penk@1599
   620
!Archiver::TarGZipArchive methodsFor:'actions'!
penk@1599
   621
penk@1599
   622
addFilesToArchiv:colOfFiles
penk@1599
   623
penk@1599
   624
    self setCommandOptions.
penk@1599
   625
    tarArchiver addFilesToArchiv:colOfFiles.
penk@1599
   626
    self synchronize.
penk@1599
   627
!
penk@1599
   628
penk@1599
   629
extractTo:aDirectory 
penk@1599
   630
penk@1599
   631
    self extractTo:aDirectory with:nil.
penk@1599
   632
!
penk@1599
   633
penk@1599
   634
extractTo:aDirectory with:col
penk@1599
   635
penk@1599
   636
    self setCommandOptions.
penk@1599
   637
    tarArchiver extractTo:aDirectory with:col.
penk@1599
   638
!
penk@1599
   639
penk@1599
   640
extractWithOutDirectoryTo:aDirectory with:files
penk@1599
   641
penk@1599
   642
    self setCommandOptions.
penk@1599
   643
    tarArchiver extractWithOutDirectoryTo:aDirectory with:files.
penk@1599
   644
!
penk@1599
   645
penk@1599
   646
listFilesFromArchiv
penk@1599
   647
penk@1599
   648
    self listFilesFromArchiv:nil
penk@1599
   649
!
penk@1599
   650
penk@1599
   651
listFilesFromArchiv:newColOfFiles
penk@1599
   652
penk@1599
   653
    self setCommandOptions.
penk@1599
   654
    ^ tarArchiver listFilesFromArchiv:newColOfFiles.
penk@1599
   655
!
penk@1599
   656
penk@1599
   657
removeFilesFromArchiv:aColOfFiles
penk@1599
   658
penk@1599
   659
    self setCommandOptions.
penk@1599
   660
    tarArchiver removeFilesFromArchiv:aColOfFiles.
penk@1599
   661
    self synchronize.
penk@1599
   662
! !
penk@1599
   663
penk@1599
   664
!Archiver::TarGZipArchive methodsFor:'actions private'!
penk@1599
   665
penk@1599
   666
setCommandOptions
penk@1599
   667
penk@1599
   668
    tarArchiver outStream:(self outStream).
penk@1599
   669
    tarArchiver errorStream:(self errorStream).
penk@1599
   670
    tarArchiver synchron:(self synchron).
penk@1599
   671
!
penk@1599
   672
penk@1599
   673
synchronize
penk@1599
   674
penk@1599
   675
    |gzipArchiver|
penk@1599
   676
penk@1599
   677
    gzipArchiver := GZipArchive with:nil.
penk@1599
   678
    gzipArchiver zipFile:(tarArchiver fileName) to:(self fileName).
penk@1599
   679
! !
penk@1599
   680
penk@1599
   681
!Archiver::TarGZipArchive methodsFor:'initialization & release'!
penk@1599
   682
penk@1599
   683
release
penk@1599
   684
penk@1599
   685
    super release.
penk@1599
   686
    tarArchiver release.
penk@1599
   687
! !
penk@1599
   688
penk@1599
   689
!Archiver class methodsFor:'documentation'!
penk@1599
   690
penk@1599
   691
version
penk@1599
   692
    ^ '$Header$'
penk@1599
   693
! !