Archiver.st
changeset 1088 f859684fd729
parent 1087 d6bfc66a3860
child 1089 128ba2ef5505
--- a/Archiver.st	Fri Sep 06 18:30:38 2002 +0200
+++ b/Archiver.st	Mon Sep 09 15:31:11 2002 +0200
@@ -1,39 +1,39 @@
 "{ Package: 'stx:libbasic2' }"
 
 Object subclass:#Archiver
-	instanceVariableNames:'process temporaryDirectory fileName outStream errorStream
-		synchron'
-	classVariableNames:''
-	poolDictionaries:''
-	category:'System-Support-FileFormats'
+        instanceVariableNames:'process temporaryDirectory fileName outStream errorStream
+                synchron'
+        classVariableNames:''
+        poolDictionaries:''
+        category:'System-Support-FileFormats'
 !
 
 Archiver subclass:#GZipArchive
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Archiver
+        instanceVariableNames:''
+        classVariableNames:''
+        poolDictionaries:''
+        privateIn:Archiver
 !
 
 Archiver subclass:#TarArchive
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Archiver
+        instanceVariableNames:''
+        classVariableNames:''
+        poolDictionaries:''
+        privateIn:Archiver
 !
 
 Archiver subclass:#TarGZipArchive
-	instanceVariableNames:'tarArchiver tarFile'
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Archiver
+        instanceVariableNames:'tarArchiver tarFile'
+        classVariableNames:''
+        poolDictionaries:''
+        privateIn:Archiver
 !
 
 Archiver subclass:#ZipArchive
-	instanceVariableNames:''
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:Archiver
+        instanceVariableNames:''
+        classVariableNames:''
+        poolDictionaries:''
+        privateIn:Archiver
 !
 
 
@@ -542,7 +542,7 @@
     archivInTemp := tempDir construct:(archivFile baseName).
     "/ copy files to be added to tempDir
     colOfFiles do:[ :file |
-        file recursiveCopyTo:(tempDir construct:(file baseName))
+        file recursiveCopyTo:(tempDir construct:(file asFilename baseName))
     ].
 
     "/ copy tar archiv to tempDir
@@ -623,7 +623,7 @@
         stream nextPutAll:archivFile asString.
         aColOfFiles do:[:el | 
             stream space.
-            stream nextPutAll:(el baseName)
+            stream nextPutAll:(el asFilename baseName)
         ].
         cmd := stream contents
     ].
@@ -647,7 +647,7 @@
     sel notNil ifTrue:[
         sel do:[:el | 
             stream space.
-            stream nextPutAll:(el fileName asString)
+            stream nextPutAll:(el asString)
         ].
     ].
     cmd := stream contents.
@@ -735,7 +735,7 @@
         file := file , '.tar'
     ].
     tarFile := self temporaryDirectory construct:file.
-    tarArchiver := TarArchive with:tarFile.
+    tarArchiver := Archiver tarArchive with:tarFile.
 ! !
 
 !Archiver::TarGZipArchive methodsFor:'actions'!
@@ -824,10 +824,22 @@
 
 !Archiver::ZipArchive class methodsFor:'command strings'!
 
+UnzipExtDirectoryOption
+    ^ $d
+!
+
+UnzipOverwriteExistingFilesOption
+    ^ $o
+!
+
 ZipArchivCommand
     ^ 'zip'
 !
 
+ZipDeleteOption
+    ^ $d
+!
+
 ZipHeaderOption
     ^ $h
 !
@@ -844,6 +856,10 @@
     ^ $r
 !
 
+ZipOverwriteExistingFilesOption
+    ^ $o
+!
+
 ZipTotalOption
     ^ $t
 !
@@ -866,6 +882,16 @@
 canRemoveFiles
 
     ^ true
+!
+
+hasLastLine
+
+    ^ true
+!
+
+hasTitleLine
+
+    ^ true
 ! !
 
 !Archiver::ZipArchive methodsFor:'actions'!
@@ -879,7 +905,7 @@
     archivInTemp := tempDir construct:(archivFile baseName).
     "/ copy files to be added to tempDir
     colOfFiles do:[ :file |
-        file recursiveCopyTo:(tempDir construct:(file baseName))
+        file recursiveCopyTo:(tempDir construct:(file asFilename baseName))
     ].
 
     "/ copy archiv to tempDir
@@ -887,7 +913,7 @@
 
     "/ addFiles to the tar archive
     cmd := self getAddFilesToArchiveCommandForArchiv:archivInTemp with:colOfFiles.
-    self executeCommand:cmd directory:(self fileName directory).
+    self executeCommand:cmd directory:tempDir.
 
     "/ copy tar archiv back
     archivInTemp copyTo:(self fileName).
@@ -904,21 +930,25 @@
 
     execDir := self fileName directory.
     cmd := self getExtractSelectedFilesCommandForDirectory:aDirectory withSelection:files.
-    self halt.
     self executeCommand:cmd directory:execDir.
 !
 
 extractWithOutDirectoryTo:aDirectory with:files
 
-    |execDir tempDir tempFile|
+    |execDir tempDir tempFile targetFile|
 
     execDir := self fileName directory.
     tempDir := self temporaryDirectory.
     self extractTo:tempDir with:files.
+    self halt.
     files do:[ : aFileString |
         tempFile := self temporaryDirectory construct:aFileString.
+        targetFile := aDirectory construct:(aFileString asFilename baseName).
+        targetFile exists ifTrue:[
+            targetFile recursiveRemove.
+        ].
         tempFile exists ifTrue:[
-            tempFile recursiveCopyTo:(aDirectory construct:(aFileString fileName asFilename baseName)).
+            tempFile recursiveCopyTo:targetFile.
         ].
     ].
 !
@@ -939,6 +969,11 @@
 !
 
 removeFilesFromArchiv:aColOfFiles
+
+    |cmd|
+
+    cmd := self getRemoveFilesFromArchivFor:aColOfFiles.
+    self executeCommand:cmd directory:(self fileName directory). 
 ! !
 
 !Archiver::ZipArchive methodsFor:'command strings'!
@@ -956,6 +991,27 @@
         stream nextPutAll:archivFile asString.
         aColOfFiles do:[:el | 
             stream space.
+            stream nextPutAll:(el asFilename baseName)
+        ].
+        cmd := stream contents
+    ].
+    ^ cmd
+!
+
+getAddFilesToTarArchiveCommand:aColOfFiles 
+    |filename cmd stream|
+
+    filename := self fileName.
+    filename exists ifTrue:[
+        stream := WriteStream on:''.
+        stream nextPutAll:self class TarArchivCommand.
+        stream space.
+        stream nextPutAll:self class TarArchivAddOption.
+        stream nextPutAll:self class TarArchivFileOption.
+        stream space.
+        stream nextPutAll:filename asString.
+        aColOfFiles do:[:el | 
+            stream space.
             stream nextPutAll:(el baseName)
         ].
         cmd := stream contents
@@ -989,7 +1045,10 @@
     stream nextPutAll:self class ZipUnzipCommand.
     stream space.
     stream nextPut:self class MinusSign.
-    stream nextPutAll:self class ZipUnzipExtDirectoryOption.
+    stream nextPut:self class UnzipOverwriteExistingFilesOption.
+    stream space.
+    stream nextPut:self class MinusSign.
+    stream nextPut:self class UnzipExtDirectoryOption.
     stream space.
     stream nextPutAll:dir asString.
     stream space.
@@ -997,7 +1056,7 @@
     sel notNil ifTrue:[
         sel do:[:el | 
             stream space.
-            stream nextPutAll:(el fileName asString)
+            stream nextPutAll:(el asString)
         ].
     ].
     cmd := stream contents.
@@ -1034,10 +1093,49 @@
 !
 
 getRemoveFilesFromArchivFor:sel 
+
+    |stream cmd|
+
+    stream := WriteStream on:''.
+    stream nextPutAll:self class ZipArchivCommand.
+    stream space.
+    stream nextPut:self class MinusSign.
+    stream nextPut:self class ZipDeleteOption.
+    stream space.
+    stream nextPutAll:self fileName asString.
+    sel do:[:el | 
+        stream space.
+        stream nextPutAll:(el asString)
+    ].
+    cmd := stream contents.
+    stream close.
+    ^ cmd
+!
+
+getRemoveFilesFromTarArchivFor:sel 
+    | stream filename|
+
+    filename := self fileName.
+    filename exists ifTrue:[
+        stream := WriteStream on:''.
+        stream nextPutAll:self class TarArchivCommand.
+        stream space.
+        stream nextPutAll:self class TarArchivDeleteOption.
+        stream space.
+        stream nextPut:self class MinusSign.
+        stream nextPutAll:self class TarArchivFileOption.
+        stream space.
+        stream nextPutAll:filename asString.
+        sel do:[:el | 
+            stream space.
+            stream nextPutAll:el
+        ].
+        ^ stream contents
+    ]
 ! !
 
 !Archiver class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.3 2002-09-06 16:30:38 penk Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.4 2002-09-09 13:31:11 penk Exp $'
 ! !