diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-02-25 16:45:38 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-02-25 16:45:38 +0000 |
commit | 2a6d51f753be8ce0655e13bc2c6ef5027ed0aa8d (patch) | |
tree | 7844f4858de732bac7d563b7863c868366193066 | |
parent | 3b1b347bc8e14eb821cf356519494dbc9b3b618d (diff) | |
download | obnam-2a6d51f753be8ce0655e13bc2c6ef5027ed0aa8d.tar.gz |
Sort directories to be locked
No test for this, since it's locale-dependent and meh.
-rw-r--r-- | obnamlib/lockmgr.py | 10 | ||||
-rw-r--r-- | obnamlib/lockmgr_tests.py | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/obnamlib/lockmgr.py b/obnamlib/lockmgr.py index 23c7a594..d57dd6af 100644 --- a/obnamlib/lockmgr.py +++ b/obnamlib/lockmgr.py @@ -34,8 +34,14 @@ class LockManager(object): def _sleep(self): # pragma: no cover time.sleep(1) + def sort(self, dirnames): + def bytelist(s): + return [ord(s) for s in str(s)] + return sorted(dirnames, key=bytelist) + def _lockname(self, dirname): return os.path.join(dirname, 'lock') + def _lock_one(self, dirname): now = self._time() @@ -55,7 +61,7 @@ class LockManager(object): def lock(self, dirnames): '''Lock ALL the directories.''' we_locked = [] - for dirname in dirnames: + for dirname in self.sort(dirnames): try: self._lock_one(dirname) except obnamlib.LockFail: @@ -66,6 +72,6 @@ class LockManager(object): def unlock(self, dirnames): '''Unlock ALL the directories.''' - for dirname in dirnames: + for dirname in self.sort(dirnames): self._unlock_one(dirname) diff --git a/obnamlib/lockmgr_tests.py b/obnamlib/lockmgr_tests.py index 8fbc52a9..2eef367b 100644 --- a/obnamlib/lockmgr_tests.py +++ b/obnamlib/lockmgr_tests.py @@ -91,3 +91,4 @@ class LockManagerTests(unittest.TestCase): self.assertFalse(self.locked(dirname)) self.assertTrue(self.locked(self.dirnames[-1])) + |