Revision a0a92e23

b/lib/utils/livelock.py
30 30
import struct
31 31
import time
32 32

  
33
from ganeti.utils.algo import NiceSort
33 34
from ganeti import pathutils
34 35

  
35 36

  
......
54 55
    """
55 56
    self.lockfile.close()
56 57
    os.remove(self.lockfile.name)
58

  
59

  
60
def GuessLockfileFor(name):
61
  """For a given name, take the latest file matching.
62

  
63
  @return: the file with the latest name matching the given
64
      prefix in LIVELOCK_DIR, or the plain name, if none
65
      exists.
66
  """
67
  lockfiles = filter(lambda n: n.startswith(name),
68
                     os.listdir(pathutils.LIVELOCK_DIR))
69
  if len(lockfiles) > 0:
70
    lockfile = NiceSort(lockfiles)[-1]
71
  else:
72
    lockfile = name
73

  
74
  return os.path.join(pathutils.LIVELOCK_DIR, lockfile)

Also available in: Unified diff