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