--- a/FileURI.st Thu Jul 10 16:33:01 2003 +0200
+++ b/FileURI.st Fri Jul 11 14:48:15 2003 +0200
@@ -32,8 +32,18 @@
^ authority notNil ifTrue:[
Filename remoteHost:authority rootComponents:pathSegments.
] ifFalse:[
- Filename rootComponents:pathSegments
+ "kludge"
+ (pathSegments first startsWith:$~) ifTrue:[
+ pathSegments first asFilename construct:(Filename rootComponents:(pathSegments copyFrom:2)).
+ ] ifFalse:[
+ Filename rootComponents:pathSegments.
+ ].
].
+
+ "
+ (URI fromString:'file:~/bla') asFilename
+ (URI fromString:'file:~root/bla') asFilename
+ "
! !
!FileURI methodsFor:'initialize'!
@@ -82,6 +92,9 @@
"
'file:/etc/group' asURI readStream contents
+ 'file:/~/.profile' asURI readStream contents
+ (URI fromString:'file:~/.profile') asFilename
+ (URI fromString:'file:~/.profile') readStream upToEnd
"
!
@@ -228,25 +241,42 @@
!
writeStreamDo:aBlock create:doCreate
+
+ ^ self writeStreamDo:aBlock create:doCreate atomic:false.
+!
+
+writeStreamDo:aBlock create:doCreate atomic:doAtomic
"evaluate a block with the write stream as first argument
and a dictionary containing attributes as second argument.
The stream is closed after aBlock has been evaluated.
- Attributes may be the mime type (key #MIME)"
+ Attributes may be the mime type (key #MIME)
+
+ If doCreate is true, a nonExistent directory will be created.
+ If doAtomic is true, files will appear atomically, by using
+ an intermediate file theat will be renamed"
- |stream fileName|
+ |stream fileName toFileName|
- fileName := self path asFilename.
+ fileName := self asFilename.
+ doAtomic ifTrue:[
+ toFileName := fileName directory construct:'.transferFile'.
+ ] ifFalse:[
+ toFileName := fileName.
+ ].
[
Stream streamErrorSignal handle:[:ex|
doCreate ifFalse:[
ex reject
].
- (fileName directory) recursiveMakeDirectory.
- stream := fileName writeStream.
+ fileName directory recursiveMakeDirectory.
+ stream := toFileName writeStream.
] do:[
- stream := fileName writeStream.
+ stream := toFileName writeStream.
].
- aBlock value:stream value:self class attributes
+ aBlock value:stream value:self class attributes.
+ doAtomic ifTrue:[
+ toFileName moveTo:fileName.
+ ]
] ensure:[
stream notNil ifTrue:[stream close]
].
@@ -263,5 +293,5 @@
!FileURI class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/FileURI.st,v 1.6 2003-07-10 14:32:51 tm Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FileURI.st,v 1.7 2003-07-11 12:46:51 stefan Exp $'
! !