Check Image Save

Report generated on Sep-15 12:00 am

Pier last restarted: Sep-04 12:52 pm

A-OK - Image file is newer (Sep-14 6:25 pm)


 (PRScheduledTaskExamples newForKernelNamed: 'Pier') reportOfFile: 'STARTED_PHARO.txt' onPageAt: '/Blog/Social Tasks/Democracy Action/Check Image Save/Report' modifyUsing: [ :restartString || imageFile transactionFile prefix lastRestart lastLine todo | prefix := ''. lastRestart := DateAndTime epoch. todo := PRPathLookup start: (PRKernel instanceNamed: 'Pier') root path: '/Blog/Social Tasks/Democracy Action'. (restartString isEmpty not and: [ (lastLine := restartString lines last) size > 74 ]) ifTrue: [ lastRestart := [ | date time | date := ((lastLine copyFrom: 51 to: 57), (lastLine copyFrom: 71 to: 74)) asDate. time := (lastLine copyFrom: 58 to: 65) asTime. DateAndTime date: date time: time ] on: Error do: [ DateAndTime epoch ]. prefix := 'Pier last restarted: ', (todo displayDateWithTimeZoneDifference: lastRestart), Character cr asString, Character cr asString ]. (imageFile := FileLocator workingDirectory / Smalltalk imageFile basename) exists ifFalse: [ 'Image file does not exist!' ] ifTrue: [ (transactionFile := FileLocator workingDirectory / 'transactions.txt') exists ifFalse: [ 'Transaction file does not exist!' ] ifTrue: [ ((FileSystem disk modificationTimeOf: transactionFile) between: (FileSystem disk modificationTimeOf: imageFile) and: lastRestart) ifTrue: [ prefix, 'NOT OK - Pier was restarted after changes but before image save' ] ifFalse: [ (FileSystem disk modificationTimeOf: imageFile) > (FileSystem disk modificationTimeOf: transactionFile) ifTrue: [ prefix, 'A-OK - Image file is newer (' , (todo displayDateWithTimeZoneDifference: (FileSystem disk modificationTimeOf: imageFile)) , ')' ] ifFalse: [ (PRKernel instanceNamed: 'Pier') persistency duration > (DateAndTime now - (FileSystem disk modificationTimeOf: transactionFile)) ifTrue: [ prefix, 'Could be OK - There are unsaved edits, but transactions is not older than persistency duration' ] ifFalse: [ prefix, 'NOT OK - There are edits that may be lost!' ] ] ] ] ] ].

Explanation:

  • Display the results for the local time, not UTC
  • Add a prefix for the last time check_pier.sh restarted pier - This is heavily dependent on the format of this scripts output
  • Sanity checks:
    • Image file must exist
    • transactions.txt should exist if anything has been edited
  • If pier was restarted after changes were made but before the image was saved, there are problems (if there are issues with checking the time of the restart, this won't work)
  • If the image file is newer than transaction.txt, there is no concern
  • otherwise:
    • Time difference between transactions.txt and the image is less than the persistency duration, then edits should be saved soon
    • Otherwise
      • If the time between now and the last edit is less than the persistency duration, then the edits should be saved soon
      • When there are edits older than the persistency and the image has not been saved since then then edits have been lost!

Other discoveries:

  • For some versions of Pharo on Fedora - Smalltalk imageFile is the memory file, it is constantly being updated - use the file name instead - Check with:
    FileSystem disk modificationTimeOf: Smalltalk imageFile