Socialmetrica/Socialmetrica.package/NitterUser.class/instance/storeContents.st

26 lines
886 B
Smalltalk
Raw Permalink Normal View History

accessing
storeContents
| objectString directory tempFile oldFile dehidratated |
dehidratated := self copy.
2022-04-14 22:40:41 +00:00
dehidratated messages: nil.
objectString := STON toStringPretty: dehidratated.
directory := self folder ensureCreateDirectory.
oldFile := directory / 'profile', 'ston'.
oldFile exists ifFalse: [
^ MarkupFile exportAsFileOn: oldFile containing: objectString ].
tempFile := MarkupFile
exportAsFileOn: FileLocator temp / self userName, 'ston'
containing: objectString.
(tempFile contents hash hex = oldFile contents hash hex) ifFalse: [
oldFile copyTo: directory /
(oldFile basenameWithoutExtension , '-',
('-' join:((oldFile creationTime asLocalStringYMDHM) splitOn: ' ')),
'.ston').
oldFile ensureDelete.
^ { 'Profile changed' -> (tempFile moveTo: oldFile)} asDictionary ].
^ { 'Same Profile' -> oldFile } asDictionary.