--- a/FileOperation.st Thu Nov 30 13:58:15 2017 +0100
+++ b/FileOperation.st Thu Nov 30 14:35:51 2017 +0100
@@ -14,7 +14,7 @@
"{ NameSpace: Smalltalk }"
Object subclass:#FileOperation
- instanceVariableNames:'errorString result actionForAll'
+ instanceVariableNames:'errorString result actionForAll browser'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
@@ -83,6 +83,37 @@
other person. No title to or ownership of the software is
hereby transferred.
"
+!
+
+documentation
+"
+ file operations which may run in the background
+
+ CopyCorrupt:
+ tries to skip over bad sectors in the input file, by skipping them and
+ writing them as zeros. Used for partial recovering of old disks and tapes.
+
+ Erase:
+ fill file with zeros (to be really erased from the disk) before removing.
+ We use this, if the file contains security relevant data (such as crypto-keys)
+
+ [instance variables:]
+ actionForAll .......... a 3-state (true/false/nil) flag, which controls if the current
+ action should be performed for all remaining files
+ (i.e. if deleting, and 'Same for all' was checked, and deletion was confirmed,
+ the remaining files are also deleted without asking again).
+ If nil, the operation will ask again for the next file.
+
+ result ................ boolean outcome
+
+ In Create:
+ createdFile ........... name of created file/directory (name as given by user)
+
+ [class variables:]
+
+ [see also:]
+
+"
! !
!FileOperation class methodsFor:'instance creation'!
@@ -145,6 +176,12 @@
^ Move moveFiles:aCollectionOfFiles to:aDestDirectory
!
+new
+ ^ self basicNew initialize
+
+ "Created: / 30-11-2017 / 14:18:59 / cg"
+!
+
renameFile:filename to:newFileString
^ Rename renameFile:filename to:newFileString
!
@@ -179,8 +216,10 @@
^ result
!
-result:something
- result := something.
+result:aBoolean
+ result := aBoolean.
+
+ "Modified (format): / 30-11-2017 / 14:18:02 / cg"
! !
!FileOperation methodsFor:'dialogs & helpers'!
@@ -344,12 +383,22 @@
onCancel:nil.
].
(withAllAction and:[answer notNil]) ifTrue:[
- actionForAll := answer
+ forAllHolder value ifTrue:[
+ actionForAll := answer
+ ].
].
^ answer
"Created: / 20-03-2012 / 11:44:34 / cg"
- "Modified: / 17-11-2017 / 13:28:04 / cg"
+ "Modified: / 30-11-2017 / 14:20:27 / cg"
+! !
+
+!FileOperation methodsFor:'initialization'!
+
+initialize
+ result := false.
+
+ "Created: / 30-11-2017 / 14:19:18 / cg"
! !
!FileOperation methodsFor:'queries'!
@@ -411,6 +460,7 @@
!FileOperation::Copy methodsFor:'accessing'!
colOfCopiedFiles
+ <resource: #obsolete>
"obsolete - bad name"
^ self collectionOfCopiedFiles
@@ -462,8 +512,10 @@
!
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean
- |newFile fileString targetDirectory suffix|
+ |newFile fileString targetDirectory suffix resources|
+ resources := AbstractFileBrowser classResources.
+
aDestFile isDirectory ifTrue:[
targetDirectory := aDestFile.
newFile := aDestFile construct:(aSourceFile baseName).
@@ -491,7 +543,7 @@
^ self.
]
] ifFalse:[
- (Dialog confirm:('Destination "%1" exists - overwrite?' bindWith:aDestFile)) ifFalse:[
+ (Dialog confirm:(resources string:'Destination "%1" exists - overwrite?' with:aDestFile)) ifFalse:[
result := false.
^ self.
]
@@ -511,7 +563,7 @@
DirectoryContents flushCachedDirectoryFor:(aSourceFile directory).
result := true.
- "Modified: / 07-02-2007 / 18:36:02 / cg"
+ "Modified: / 30-11-2017 / 14:30:43 / cg"
!
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy
@@ -594,7 +646,7 @@
basicCopyFile:sourceFile to:destFile
"this is a copy which is tolerant w.r.t. read errors.
- Wheneven a read fails, a number of retries is performed
+ Whenever a read fails, a number of retries is performed
(with smaller buffer sizes) and, a block of zeros is eventually written.
This allows for partially corrupted data to be read from a tape or disk."
@@ -724,6 +776,7 @@
"Created: / 07-02-2007 / 18:40:32 / cg"
"Modified: / 21-06-2010 / 14:25:22 / cg"
+ "Modified (comment): / 30-11-2017 / 14:31:27 / cg"
! !
!FileOperation::CopyCorrupted methodsFor:'defaults'!
@@ -736,10 +789,11 @@
defectBlockCopySize
"/ ^ 256
- ^ 128*1024
+ "/ ^ 128*1024
+ ^ 4*1024
"Created: / 21-06-2010 / 14:22:23 / cg"
- "Modified: / 27-11-2010 / 18:06:10 / cg"
+ "Modified: / 30-11-2017 / 14:32:48 / cg"
!
defectBlockRetryCount
@@ -813,14 +867,9 @@
!FileOperation::Create methodsFor:'actions'!
createDirectoryIn:startDirectory
- |defaultDirectory|
+ ^ self createDirectoryIn:startDirectory initialAnswer:nil
- "/ stupid - that one already exists
-"/ LastCreatedDirectory notNil ifTrue:[
-"/ defaultDirectory := LastCreatedDirectory baseName.
-"/ ].
-
- ^ self createDirectoryIn:startDirectory initialAnswer:defaultDirectory
+ "Modified: / 30-11-2017 / 14:17:01 / cg"
!
createHardLinkIn:aFile
@@ -836,9 +885,11 @@
!
operationError:msg
- self result:false.
+ result := false.
Dialog warn:msg.
self errorString:msg.
+
+ "Modified: / 30-11-2017 / 14:25:12 / cg"
! !
!FileOperation::Create methodsFor:'actions-basic'!
@@ -859,11 +910,11 @@
okLabel:(resources string:'Create')
title:(resources string:'Create Directory')
onCancel:[
- self result:false.
+ result := false.
^ self
].
newName isEmpty ifTrue:[
- self result:false.
+ result := false.
^ self
].
newDir := startDirectory construct:newName.
@@ -883,11 +934,11 @@
newDir makeDirectory
].
- self createdFile:newDir.
+ createdFile := newDir.
LastCreatedDirectory := newDir.
result := true.
- "Modified: / 05-09-2006 / 11:52:48 / cg"
+ "Modified: / 30-11-2017 / 14:27:54 / cg"
!
createFileIn:aFile
@@ -914,12 +965,12 @@
okLabel:(resources string:'Create')
title:(resources string:'Create File')
onCancel:[
- self result:false.
+ result := false.
^ self
].
newName isEmptyOrNil ifTrue:[
- self result:false.
+ result := false.
^ self
].
@@ -930,8 +981,8 @@
newFile fileSize == 0 ifTrue:[
Dialog
information:(resources stringWithCRs:'An empty "%1" (i.e. with size 0) already existed.' with:newName).
- self createdFile:newFile.
- self result:true.
+ createdFile := newFile.
+ result := true.
^ self
].
(Dialog
@@ -939,12 +990,12 @@
yesLabel:(resources string:'Truncate')
noLabel:(resources string:'Cancel'))
ifFalse:[
- self result:false.
+ result := false.
^ self
].
] ifFalse:[
Dialog warn:(resources stringWithCRs:'"%1" already exists as a %2' with:newFile fileType).
- self result:false.
+ result := false.
^ self
].
].
@@ -952,16 +1003,18 @@
FileStream openErrorSignal handle:[:ex|
msg := resources string:'Cannot create file "%1" (%2)' with:newName with:(FileStream lastErrorString).
errorString := msg.
- self result:false.
+ result := false.
Dialog warn:errorString.
^ self.
] do:[
aStream := newFile newReadWriteStream.
].
aStream close.
- self createdFile:newFile.
+ createdFile := newFile.
LastCreatedFile := newFile.
- self result:true.
+ result := true.
+
+ "Modified: / 30-11-2017 / 14:28:07 / cg"
!
createLinkIn:aFile soft:symbolic
@@ -992,12 +1045,13 @@
box showAtPointer.
box accepted ifFalse:[
- self result:false.
- ] ifTrue:[
- self doCreateLinkFrom:(oldPath value) to:(newPath value) soft:symbolic.
+ result := false.
+ ^ self
].
+
+ self doCreateLinkFrom:(oldPath value) to:(newPath value) soft:symbolic.
- "Modified: / 24-07-2011 / 08:24:14 / cg"
+ "Modified: / 30-11-2017 / 14:24:54 / cg"
!
doCreateLinkFrom:oldPath to:newPathArg soft:symbolic
@@ -1010,11 +1064,11 @@
resources := AbstractFileBrowser classResources.
oldPath isNil ifTrue:[
- self operationError:'Missing source'.
+ self operationError:(resources string:'Missing source: "%1"' with:oldPath allBold).
^ self.
].
newPath isNil ifTrue:[
- self operationError:'Missing link name (target)'.
+ self operationError:(resources string:'Missing link name (target)').
^ self.
].
@@ -1029,25 +1083,25 @@
].
newPathFile exists ifTrue:[
- self operationError:(resources string:'%1 already exists' with:newPath allBold).
+ self operationError:(resources string:'"%1" already exists' with:newPath allBold).
^ self.
].
oldPathFile exists ifFalse:[
symbolic ifTrue:[
oldPathFile isAbsolute ifTrue:[
- self operationError:(resources string:'%1 does not exist' with:oldPath allBold).
+ self operationError:(resources string:'"%1" does not exist' with:oldPath allBold).
^ self.
].
(newPathFile directory construct:oldPath) exists ifFalse:[
- Dialog warn:(resources string:'%1 does not exist (Warning only)' with:oldPath allBold).
+ Dialog warn:(resources string:'"%1" does not exist (Warning only)' with:oldPath allBold).
].
] ifFalse:[
- self operationError:(resources string:'%1 does not exist' with:oldPath allBold).
+ self operationError:(resources string:'"%1" does not exist' with:oldPath allBold).
^ self.
].
].
((symbolic not) and:[oldPathFile isDirectory]) ifTrue:[
- self operationError:(resources string:'%1 is a directory' with:oldPath allBold).
+ self operationError:(resources string:'"%1" is a directory' with:oldPath allBold).
^ self.
].
ErrorSignal handle:[:ex |
@@ -1058,9 +1112,11 @@
] ifFalse:[
newPathFile createAsHardLinkTo:oldPathFile.
].
- self createdFile:newPathFile.
- self result:true.
+ createdFile := newPathFile.
+ result := true.
].
+
+ "Modified: / 30-11-2017 / 14:28:15 / cg"
! !
!FileOperation::Delete class methodsFor:'actions'!