File locking: Difference between revisions

From FreeMind
Jump to navigationJump to search
(+)
 
(expand)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
There is an experimental file locking feature, disabled by default. To enable the feature, choose Tools > Preferences > Environment > Files > Experimental File Locking.  
There is an experimental file locking feature, disabled by default. To enable the feature, choose Tools > Preferences > Environment > Files > Experimental File Locking. The feature prevents two users from editing a mind map at the same time, thereby overwriting each other's changes. Available since FreeMind [[Release 0.6.5|0.6.5]].
 
==Algorithm==
* When opening a mind map, FreeMind creates a lock file unless one already exists.
* After successful creation of the lock file, FreeMind refreshes the lock file every 4 minutes, by writing the user name and the current time into the lock file.<!-- Code: The refresh is in a thread made via LockManager class. The lock refresh is ensured by LockManager.run(), which calls LockManager.writeSemaphoreFile(). -->
* Upon opening a mind map, if a fresh lock file exists, FreeMind opens a warning pop-up window stating which user edits the mind map and opens the mind map as read-only. A lock file is considered fresh if the time written into it is no older than 5 minutes, which is the 4 minutes stated above + 1 minute as a reserve. A read-only mind map can still be edited but cannot be saved and has to be saved-as if the content is to be preserved. <!-- Code: the check for staleness is in LockManager.tryToLock(), in "if (timeDifference > lockSafetyPeriod)" -->
* Upon opening a mind map, if a stale lock file exists, FreeMind deletes the stale lock file and opens the mind map for writing. <!-- Code: see the item above -->
* On Windows, the lock file is attempted to be made a hidden file. <!-- Code: LockManager.tryToLock() and Tools.setHidden() -->
* Detail: The lock file name is the name of the mind map prefixed with $~ and suffixed with ~. <!-- Code: LockManager.getSemaphoreFile() -->
 
==Reliability==
The feature is experimental. The [[#Bug reports]] section below contains a bug report that (a) provides a bug fix, and (b) reports that, after the bug fix, the reporting user is happy with the feature.
 
==Implementation==
* Class [https://sourceforge.net/p/freemind/code/ci/1.1.0/tree/freemind/freemind/modes/mindmapmode/MindMapMapModel.java MindMapMapModel]
** Nested class LockManager
** MindMapMapModel.tryToLock(): calls lockManager.tryToLock().
** MindMapMapModel.destroy(): calls lockManager.releaseLock() and lockManager.releaseTimer().
* Class [https://sourceforge.net/p/freemind/code/ci/1.1.0/tree/freemind/freemind/main/Tools.java Tools], Tools.setHidden().
 
==Bug reports==
* [https://sourceforge.net/p/freemind/bugs/976/ fix for experimental file locking on windows], 2010-09-05 - contains a fix for LockManager.writeSemaphoreFile() consisting in catching an exception.


==See also==
==See also==
* [[Multiple users]]
* [[Collaboration]]


[[Category:Development]]
[[Category:Development]]

Latest revision as of 07:15, 24 March 2016

There is an experimental file locking feature, disabled by default. To enable the feature, choose Tools > Preferences > Environment > Files > Experimental File Locking. The feature prevents two users from editing a mind map at the same time, thereby overwriting each other's changes. Available since FreeMind 0.6.5.

Algorithm

  • When opening a mind map, FreeMind creates a lock file unless one already exists.
  • After successful creation of the lock file, FreeMind refreshes the lock file every 4 minutes, by writing the user name and the current time into the lock file.
  • Upon opening a mind map, if a fresh lock file exists, FreeMind opens a warning pop-up window stating which user edits the mind map and opens the mind map as read-only. A lock file is considered fresh if the time written into it is no older than 5 minutes, which is the 4 minutes stated above + 1 minute as a reserve. A read-only mind map can still be edited but cannot be saved and has to be saved-as if the content is to be preserved.
  • Upon opening a mind map, if a stale lock file exists, FreeMind deletes the stale lock file and opens the mind map for writing.
  • On Windows, the lock file is attempted to be made a hidden file.
  • Detail: The lock file name is the name of the mind map prefixed with $~ and suffixed with ~.

Reliability

The feature is experimental. The #Bug reports section below contains a bug report that (a) provides a bug fix, and (b) reports that, after the bug fix, the reporting user is happy with the feature.

Implementation

  • Class MindMapMapModel
    • Nested class LockManager
    • MindMapMapModel.tryToLock(): calls lockManager.tryToLock().
    • MindMapMapModel.destroy(): calls lockManager.releaseLock() and lockManager.releaseTimer().
  • Class Tools, Tools.setHidden().

Bug reports

See also