[GRASS-SVN] r73335 - grass/trunk/lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Sep 15 18:11:45 PDT 2018


Author: wenzeslaus
Date: 2018-09-15 18:11:45 -0700 (Sat, 15 Sep 2018)
New Revision: 73335

Modified:
   grass/trunk/lib/init/grass.py
Log:
init: remove lock from the current mapset (fixes #3631)

Do not remove lock based on the path to the initially locked file,
but instead use the rc file point to by GISRC (assumed stable within this proccess)
to find out the current mapset and remove lock file there.

Now a sequence start in mapset A, switch to B, exit removes all lock files.
Before, only the A lock file was removed, specifically the lock file was left
in the mapset exited from.


Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2018-09-15 20:37:12 UTC (rev 73334)
+++ grass/trunk/lib/init/grass.py	2018-09-16 01:11:45 UTC (rev 73335)
@@ -205,7 +205,6 @@
     """Holds directories and files which needs to be cleaned or deleted"""
     def __init__(self):
         self.mapset_path = None
-        self.lockfile = None
         self.tmpdir = None
 
     def cleanup(self):
@@ -220,9 +219,6 @@
             tmpdir_mapset = os.path.join(self.mapset_path, ".tmp")
             cleanup_dir(tmpdir_mapset)
             try_rmdir(tmpdir_mapset)
-        # remove lock-file if requested
-        if self.lockfile:
-            try_remove(self.lockfile)
 
 
 def fatal(msg):
@@ -1435,6 +1431,17 @@
     return lockfile
 
 
+# TODO: the gisrcrc here does not make sense, remove it from load_gisrc
+def unlock_gisrc_mapset(gisrc, gisrcrc):
+    """Unlock mapset from the gisrc file"""
+    settings = load_gisrc(gisrc, gisrcrc)
+    lockfile = os.path.join(settings.full_mapset, ".gislock")
+    # this fails silently, perhaps a warning would be helpful to
+    # catch cases when removal was not possible due to e.g. another
+    # session force-removing the file (unlocking the mapset)
+    try_remove(lockfile)
+
+
 def make_fontcap():
     # TODO: is GRASS_FONT_CAP ever defined? It seems it must be defined in system
     fc = os.getenv('GRASS_FONT_CAP')
@@ -2141,9 +2148,12 @@
     cleaner.mapset_path = mapset_settings.full_mapset
 
     # check and create .gislock file
-    cleaner.lockfile = lock_mapset(mapset_settings.full_mapset, user=user,
-                                   force_gislock_removal=params.force_gislock_removal,
-                                   grass_gui=grass_gui)
+    lock_mapset(mapset_settings.full_mapset, user=user,
+                force_gislock_removal=params.force_gislock_removal,
+                grass_gui=grass_gui)
+    # unlock the mapset which is current at the time of turning off
+    # in case mapset was changed
+    atexit.register(lambda: unlock_gisrc_mapset(gisrc, gisrcrc))
 
     # build user fontcap if specified but not present
     make_fontcap()



More information about the grass-commit mailing list