소스 검색

init: remove lock from the current mapset (fixes https://trac.osgeo.org/grass/ticket/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.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@73335 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 6 년 전
부모
커밋
c4ebe34c50
1개의 변경된 파일17개의 추가작업 그리고 7개의 파일을 삭제
  1. 17 7
      lib/init/grass.py

+ 17 - 7
lib/init/grass.py

@@ -205,7 +205,6 @@ class Cleaner(object):  # pylint: disable=R0903
     """Holds directories and files which needs to be cleaned or deleted"""
     """Holds directories and files which needs to be cleaned or deleted"""
     def __init__(self):
     def __init__(self):
         self.mapset_path = None
         self.mapset_path = None
-        self.lockfile = None
         self.tmpdir = None
         self.tmpdir = None
 
 
     def cleanup(self):
     def cleanup(self):
@@ -220,9 +219,6 @@ class Cleaner(object):  # pylint: disable=R0903
             tmpdir_mapset = os.path.join(self.mapset_path, ".tmp")
             tmpdir_mapset = os.path.join(self.mapset_path, ".tmp")
             cleanup_dir(tmpdir_mapset)
             cleanup_dir(tmpdir_mapset)
             try_rmdir(tmpdir_mapset)
             try_rmdir(tmpdir_mapset)
-        # remove lock-file if requested
-        if self.lockfile:
-            try_remove(self.lockfile)
 
 
 
 
 def fatal(msg):
 def fatal(msg):
@@ -1435,6 +1431,17 @@ def lock_mapset(mapset_path, force_gislock_removal, user, grass_gui):
     return lockfile
     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():
 def make_fontcap():
     # TODO: is GRASS_FONT_CAP ever defined? It seems it must be defined in system
     # TODO: is GRASS_FONT_CAP ever defined? It seems it must be defined in system
     fc = os.getenv('GRASS_FONT_CAP')
     fc = os.getenv('GRASS_FONT_CAP')
@@ -2141,9 +2148,12 @@ def main():
     cleaner.mapset_path = mapset_settings.full_mapset
     cleaner.mapset_path = mapset_settings.full_mapset
 
 
     # check and create .gislock file
     # 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
     # build user fontcap if specified but not present
     make_fontcap()
     make_fontcap()