[squeak-dev] The Trunk: Files-dtl.199.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Nov 25 18:59:10 UTC 2022


David T. Lewis uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-dtl.199.mcz

==================== Summary ====================

Name: Files-dtl.199
Author: dtl
Time: 25 November 2022, 1:59:09.407907 pm
UUID: d67aa170-9fb2-45df-9981-5cd5e6e7e5b9
Ancestors: Files-ct.198

Add ChangeLogStream to allow the changes log to be maintained within the image rather than as an external file. Provide a "Cache changes file" preference for changing the configuration. UTF8 encoding is assumed, and several conversion methods are duplicated from MultiByteFileStream. Inspired by the original Scott Wallace implementation circa 1996, see SystemDictionary>>internalizeChangeLog and SystemDictionary>>internalizeSources in early Squeak images.

=============== Diff against Files-ct.198 ===============

Item was added:
+ ReadWriteStream subclass: #ChangeLogStream
+ 	instanceVariableNames: 'TextConverter'
+ 	classVariableNames: ''
+ 	poolDictionaries: ''
+ 	category: 'Files-System'!
+ 
+ !ChangeLogStream commentStamp: 'dtl 11/5/2022 16:22' prior: 0!
+ A ChangeLogStream is a memory resident changes log, equivalent to the traditional file based changes but not stored on the external file system. UTF8 encoding is assumed for all sources and a UTF8TextConverter is used for reading and writing to the stream.
+ !

Item was added:
+ ----- Method: ChangeLogStream>>basicNext:putAll:startingAt: (in category 'private basic') -----
+ basicNext: anInteger putAll: aCollection startingAt: startIndex
+ 
+ 	^super next: anInteger putAll: aCollection startingAt: startIndex!

Item was added:
+ ----- Method: ChangeLogStream>>basicNextPut: (in category 'private basic') -----
+ basicNextPut: char
+ 
+ 	^ super nextPut: char.
+ !

Item was added:
+ ----- Method: ChangeLogStream>>basicNextPutAll: (in category 'private basic') -----
+ basicNextPutAll: aString
+ 
+ 	^ super nextPutAll: aString.
+ !

Item was added:
+ ----- Method: ChangeLogStream>>converter (in category 'converting') -----
+ converter
+ 	"Assume UTF8 for all sources"
+ 
+ 	^TextConverter ifNil: [TextConverter := UTF8TextConverter new].!

Item was added:
+ ----- Method: ChangeLogStream>>isReadOnly (in category 'testing') -----
+ isReadOnly
+ 	^false!

Item was added:
+ ----- Method: ChangeLogStream>>nextChunkText (in category 'fileIn/Out') -----
+ nextChunkText
+ 	"Deliver the next chunk as a Text.  Decode the following ]style[ chunk if present.  Position at start of next real chunk."
+ 	
+ 	^self converter nextChunkTextFromStream: self!

Item was added:
+ ----- Method: ChangeLogStream>>nextPut: (in category 'accessing') -----
+ nextPut: aCharacter
+ 
+ 	^self converter nextPut: aCharacter toStream: self!

Item was added:
+ ----- Method: ChangeLogStream>>nextPutAll: (in category 'accessing') -----
+ nextPutAll: aCollection
+ 
+ 	^self converter nextPutAll: aCollection toStream: self!

Item was added:
+ ----- Method: ChangeLogStream>>readOnlyCopy (in category 'converting') -----
+ readOnlyCopy
+ 	^ self!

Item was added:
+ ----- Method: ChangeLogStream>>reopen (in category 'converting') -----
+ reopen
+ 	^self!

Item was changed:
  SequenceableCollection subclass: #SourceFileArray
  	instanceVariableNames: ''
+ 	classVariableNames: 'CachedChanges'
- 	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Files-System'!
  
  !SourceFileArray commentStamp: '<historical>' prior: 0!
  This class is an abstract superclass for source code access mechanisms. It defines the messages that need to be understood by those subclasses that store and retrieve source chunks on files, over the network or in databases.
  The first concrete subclass, StandardSourceFileArray, supports access to the traditional sources and changes files. Other subclasses might implement multiple source files for different applications, or access to a network source server.!

Item was added:
+ ----- Method: SourceFileArray class>>cachedChanges (in category 'internalize changes') -----
+ cachedChanges
+ 	"When present, CachedChanges replaces the traditional external changes
+ 	file with an internal stream in the image."
+ 	^CachedChanges!

Item was added:
+ ----- Method: SourceFileArray class>>changeLogContents (in category 'internalize changes') -----
+ changeLogContents
+ 	| changes fs contents |
+ 	changes := SourceFiles at: 2.
+ 	(changes isKindOf: FileStream)
+ 		ifTrue: [[fs := StandardFileStream "Use StandardFileStream, not FileStream concreteStream, to avoid WideString conversion"
+ 				readOnlyFileNamed: changes name.
+ 			fs binary.
+ 			contents := fs upToEnd]
+ 				ensure: [fs close].
+ 			"Smalltalk openSourceFiles."
+ 			^ contents asString]
+ 		ifFalse: [^ changes contents]!

Item was added:
+ ----- Method: SourceFileArray class>>externalizeChangeLog (in category 'internalize changes') -----
+ externalizeChangeLog
+ 	"Move the changes log to an external file. This is the traditional packaging, in
+ 	which the sources file and changes file are maintained separately from the
+ 	image file."
+ 	self safeToExportChanges
+ 		ifTrue: [ | fs |
+ 			[fs := FileStream fileNamed: Smalltalk changesName.
+ 			fs binary.
+ 			fs nextPutAll: CachedChanges contents.
+ 			CachedChanges := nil]
+ 				ensure: [ fs close ].
+ 			Smalltalk openSourceFiles].
+ !

Item was added:
+ ----- Method: SourceFileArray class>>internalizeChangeLog (in category 'internalize changes') -----
+ internalizeChangeLog
+ 	"Move the change log to an internal stream and maintain it within the image.
+ 	This configuration may be risky because the record of recently logged changes
+ 	is no longer available in a separate external file. If the image file itself becomes
+ 	unusable, the recent changes log file will not be available."
+ 	(ChangeLogStream with: self changeLogContents)
+ 		ifNotNil: [:strm | 
+ 			CachedChanges := strm.
+ 			SourceFiles at: 2 put: CachedChanges]!

Item was added:
+ ----- Method: SourceFileArray class>>internalizeChanges (in category 'internalize changes') -----
+ internalizeChanges
+ 
+ 	<preference: 'Cache changes file'
+ 	category: 'Files'
+ 	description: 'Log changes to internal stream rather than external file. External changes file will not be available for error recovery.'
+ 	type: #Boolean>
+ 	^CachedChanges notNil
+ !

Item was added:
+ ----- Method: SourceFileArray class>>internalizeChanges: (in category 'internalize changes') -----
+ internalizeChanges: internalize
+ 
+ 	internalize
+ 		ifTrue: [ self internalizeChangeLog ]
+ 		ifFalse: [self externalizeChangeLog ].!

Item was added:
+ ----- Method: SourceFileArray class>>safeToExportChanges (in category 'internalize changes') -----
+ safeToExportChanges
+ 	"Changes log is currently internal, and there is no external changes file with
+ 	the name that would be used for saving externally or the user confirms that
+ 	it safe to overwrite that existing file. Existing changes file will be removed if
+ 	user confirms."
+ 
+ 	^ CachedChanges
+ 		ifNil: [ false ]
+ 		ifNotNil: [ (FileDirectory default fileExists: Smalltalk changesName)
+ 			ifTrue: [ | response |
+ 				(response :=self confirm: Smalltalk changesName , ' exists, overwrite?')
+ 					ifTrue: [[ FileDirectory default deleteFileNamed: Smalltalk changesName ]
+ 						on: Error do: [ self notify: 'cannot delete ', Smalltalk changesName. ^false ]].
+ 				^ response ]
+ 			ifFalse: [true]].
+ 
+ !



More information about the Squeak-dev mailing list