Skip to content

Commit

Permalink
Ensure files are properly truncated before use. FileSystem previously…
Browse files Browse the repository at this point in the history
… worked around this issue but truncating to current stream position on #flush.

See: GemTalk/FileSystemGs#53
  • Loading branch information
kurtkilpela committed Jan 30, 2023
1 parent dd0ad5c commit 4c0e0f6
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,8 @@ RwAbstractRowanProjectLoadComponentV2 >> exportDoitsToUrl: directoryUrl [
ifNotNil: [ :doitString |
| fileRef |
fileRef := doitsRoot / doitName , 'st'.
fileRef exists
ifFalse: [ fileRef ensureCreateFile ].
fileRef
writeStreamDo: [ :fileStream | fileStream nextPutAll: doitString ] ] ] ] ]
writeStreamDo: [ :fileStream | fileStream truncate; nextPutAll: doitString ] ] ] ] ]
ifFalse: [ self error: 'unsupported url scheme ' , url schemeName printString ]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ RwModificationFiletreeWriterVisitor >> _filetreePackagePropertyDictFor: aPackage
"create default properties file"
propertiesFile
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _toJSON:
(self class orderedDictionaryClass new
Expand All @@ -165,6 +166,7 @@ RwModificationFiletreeWriterVisitor >> _filetreeProjectPropertyDictFor: aProject
propertiesFile
writeStreamDo: [:aStream |
| dict |
aStream truncate.
dict := (self class orderedDictionaryClass new)
at: 'packageExtension' put: '.', self packageExtension;
at: 'Metadata' put: self monticelloMetadata;
Expand Down Expand Up @@ -294,6 +296,7 @@ RwModificationFiletreeWriterVisitor >> addedMethod: aMethodModification [

(methodDir / methodFileName, 'st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< methodDefinition protocol
<< self _newLine
Expand All @@ -319,6 +322,7 @@ RwModificationFiletreeWriterVisitor >> addedMethodExtension: aMethodExtensionMod

(methodDir / methodFileName, 'st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< methodDefinition protocol
<< self _newLine
Expand All @@ -335,6 +339,7 @@ RwModificationFiletreeWriterVisitor >> addedPackage: aPackageModification [
self _packageSourceDir ensureCreateDirectory.
(self _packageSourceDir / 'properties.json')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< '{'
<< self _newLine
Expand Down Expand Up @@ -376,6 +381,7 @@ RwModificationFiletreeWriterVisitor >> changedMethod: aMethodModification [

(methodDir / methodFileName, 'st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< methodDefinition protocol
<< self _newLine
Expand Down Expand Up @@ -480,11 +486,13 @@ RwModificationFiletreeWriterVisitor >> processClass: aClassModification [

(self _classSourceDir / 'README.md')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _commentOf: self currentClassDefinition) ].

(self _classSourceDir / 'properties.json')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _typeClassDefinitionOf: self currentClassDefinition)
<< self _newLine ].
Expand Down Expand Up @@ -513,6 +521,7 @@ RwModificationFiletreeWriterVisitor >> processClassExtension: aClassExtensionMod
self _classExtensionSourceDir ensureCreateDirectory.
(self _classExtensionSourceDir / 'properties.json')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _classExtensionOf: self currentClassExtension)
<< self _newLine ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ RwModificationFiletreeWriterVisitorV2 >> _filetreePackagePropertyDictFor: aPacka
"create default properties file"
propertiesFile
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _toJSON:
(self class orderedDictionaryClass new
Expand All @@ -165,6 +166,7 @@ RwModificationFiletreeWriterVisitorV2 >> _filetreeProjectPropertyDictFor: aProje
propertiesFile
writeStreamDo: [:aStream |
| dict |
aStream truncate.
dict := (self class orderedDictionaryClass new)
at: 'packageExtension' put: '.', self packageExtension;
at: 'Metadata' put: self monticelloMetadata;
Expand Down Expand Up @@ -294,6 +296,7 @@ RwModificationFiletreeWriterVisitorV2 >> addedMethod: aMethodModification [

(methodDir / methodFileName, 'st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< methodDefinition protocol
<< self _newLine
Expand All @@ -319,6 +322,7 @@ RwModificationFiletreeWriterVisitorV2 >> addedMethodExtension: aMethodExtensionM

(methodDir / methodFileName, 'st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< methodDefinition protocol
<< self _newLine
Expand All @@ -335,6 +339,7 @@ RwModificationFiletreeWriterVisitorV2 >> addedPackage: aPackageModification [
self _packageSourceDir ensureCreateDirectory.
(self _packageSourceDir / 'properties.json')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< '{'
<< self _newLine
Expand Down Expand Up @@ -376,6 +381,7 @@ RwModificationFiletreeWriterVisitorV2 >> changedMethod: aMethodModification [

(methodDir / methodFileName, 'st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< methodDefinition protocol
<< self _newLine
Expand Down Expand Up @@ -481,11 +487,13 @@ RwModificationFiletreeWriterVisitorV2 >> processClass: aClassModification [

(self _classSourceDir / 'README.md')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _commentOf: self currentClassDefinition) ].

(self _classSourceDir / 'properties.json')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _typeClassDefinitionOf: self currentClassDefinition)
<< self _newLine ].
Expand Down Expand Up @@ -514,6 +522,7 @@ RwModificationFiletreeWriterVisitorV2 >> processClassExtension: aClassExtensionM
self _classExtensionSourceDir ensureCreateDirectory.
(self _classExtensionSourceDir / 'properties.json')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< (self _classExtensionOf: self currentClassExtension)
<< self _newLine ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ RwModificationPharoTonelFormatV1WriterVisitorV2 >> addedPackage: aPackageModific
self _packageSourceDir ensureCreateDirectory.
self _packageSourceDir / 'package.st'
writeStreamDo: [ :aStream |
aStream truncate.
aStream << 'Package ' << (self _toSTON: exportedPackageProperties)
<< self _newLine ].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ RwModificationTonelWriterVisitor >> addedPackage: aPackageModification [
self _packageSourceDir ensureCreateDirectory.
(self _packageSourceDir / 'package.st')
writeStreamDo: [:aStream |
aStream truncate.
aStream
<< 'Package '
<< (self _toSTON: { #name -> currentPackageDefinition name } asDictionary)
Expand Down Expand Up @@ -256,6 +257,7 @@ RwModificationTonelWriterVisitor >> processClass: aClassModification [
self _classSourceFile
writeStreamDo: [:aStream |
aStream truncate.
self _writeClassDefinition: currentClassDefinition on: aStream.
self _writeClassSideMethodDefinitions: currentClassDefinition on: aStream.
self _writeInstanceSideMethodDefinitions: currentClassDefinition on: aStream ]
Expand All @@ -271,6 +273,7 @@ RwModificationTonelWriterVisitor >> processClassExtension: aClassExtensionModifi
ifFalse: [
self _classExtensionSourceFile
writeStreamDo: [:aStream |
aStream truncate.
self _writeClassExtension: currentClassExtension on: aStream.
self _writeClassSideMethodDefinitions: currentClassExtension on: aStream.
self _writeInstanceSideMethodDefinitions: currentClassExtension on: aStream ] ]
Expand All @@ -290,6 +293,7 @@ RwModificationTonelWriterVisitor >> processProject: aProjectModification [
propertiesFile exists
ifFalse: [
propertiesFile writeStreamDo: [ :fileStream |
fileStream truncate.
fileStream
nextPutAll: '{ #format : ' , format printString , '}';
lf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ RwModificationTonelWriterVisitorV2 >> addedPackage: aPackageModification [
self _packageSourceDir ensureCreateDirectory.
self _packageSourceDir / 'package.st'
writeStreamDo: [ :aStream |
aStream truncate.
aStream << 'Package ' << (self _toSTON: exportedPackageProperties)
<< self _newLine ].
Expand Down Expand Up @@ -278,6 +279,7 @@ RwModificationTonelWriterVisitorV2 >> processClass: aClassModification [
self _classSourceFile
writeStreamDo: [:aStream |
aStream truncate.
self _writeClassDefinition: currentClassDefinition on: aStream.
self _writeClassSideMethodDefinitions: currentClassDefinition on: aStream.
self _writeInstanceSideMethodDefinitions: currentClassDefinition on: aStream ]
Expand All @@ -293,6 +295,7 @@ RwModificationTonelWriterVisitorV2 >> processClassExtension: aClassExtensionModi
ifFalse: [
self _classExtensionSourceFile
writeStreamDo: [:aStream |
aStream truncate.
self _writeClassExtension: currentClassExtension on: aStream.
self _writeClassSideMethodDefinitions: currentClassExtension on: aStream.
self _writeInstanceSideMethodDefinitions: currentClassExtension on: aStream ] ]
Expand All @@ -312,6 +315,7 @@ RwModificationTonelWriterVisitorV2 >> processProject: aProjectModification [
propertiesFile exists
ifFalse: [
propertiesFile writeStreamDo: [ :fileStream |
fileStream truncate.
fileStream
nextPutAll: '{ #format : ' , format printString , '}';
lf;
Expand Down
1 change: 1 addition & 0 deletions rowan/src/Rowan-DefinitionsV2/RwResolvedProjectV2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ RwResolvedProjectV2 >> exportPackages: diskProjectSetDefinition packagesRoot: pa
sourceProjectSetDefinition := diskProjectSetDefinition.
packagesRoot / 'properties' , 'st'
writeStreamDo: [ :fileStream |
fileStream truncate.
fileStream
nextPutAll: '{ ';
lf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RwAbstractRowanProjectLoadComponentV2 >> _exportToUrl: directoryUrl [
fileRef
writeStreamDo: [ :stream |
| string |
stream truncate.
string := STON toStringPretty: self.
stream nextPutAll: string.
^ self ] ].
Expand All @@ -33,6 +34,7 @@ RwAbstractRowanProjectLoadComponentV2 >> _exportToUrl: directoryUrl [
/ self name , 'ston'
writeStreamDo: [ :stream |
| string |
stream truncate.
string := STON toStringPretty: self.
stream nextPutAll: string.
^ self ] ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ RwLoadSpecificationV2 >> diskUrl: anUrlString [
{ #category : 'exporting' }
RwLoadSpecificationV2 >> exportTo: directoryReference [
directoryReference / self specName , 'ston'
writeStreamDo: [ :fileStream | self exportToStream: fileStream ]
writeStreamDo:
[ :fileStream |
fileStream truncate.
self exportToStream: fileStream ]
]

{ #category : 'exporting' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ RwProjectSpecificationV2 >> componentsPath: aString [
RwProjectSpecificationV2 >> exportTo: directoryReference [

(directoryReference / self projectSpecPath / self specName, 'ston')
writeStreamDo: [ :fileStream | STON put: self copy initializeForExport onStreamPretty: fileStream ]
writeStreamDo: [ :fileStream |
fileStream truncate.
STON put: self copy initializeForExport onStreamPretty: fileStream ]
]

{ #category : 'comparing' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RwResolvedProjectV2 >> exportPharoTonelFormatV1Packages: diskProjectSetDefinitio
| projectSetDefinition visitor projectSetModification writerVisitorClass |
packagesRoot / 'properties' , 'st'
writeStreamDo: [ :fileStream |
fileStream truncate.
fileStream
nextPutAll: '{ ';
lf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,7 @@ RwTestProjectLibraryGenerator >> _finishCommitAndPush: specName loadSpecificatio
ifNotNil: [
resolvedRepository repositoryRoot / 'README.md'
writeStreamDo: [ :fileStream |
fileStream truncate.
fileStream
nextPutAll: '# ' , projectName , ' - ' , specName;
lf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ RwTestProjectLibraryIndexCard >> exportTo: directoryReference [
{ #category : 'export' }
RwTestProjectLibraryIndexCard >> exportTo: directoryReference as: fileName [
directoryReference / fileName
writeStreamDo: [ :fileStream | self exportToStream: fileStream ]
writeStreamDo: [ :fileStream |
fileStream truncate.
self exportToStream: fileStream ]
]

{ #category : 'export' }
Expand Down

0 comments on commit 4c0e0f6

Please sign in to comment.