Skip to content

Commit

Permalink
More robust directory handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrowley committed Feb 2, 2010
1 parent c1c1f99 commit ff8484a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
8 changes: 6 additions & 2 deletions countd/permanent/binarysearch.py
Expand Up @@ -21,8 +21,12 @@ class Deltas(abstract.Deltas):
WRITE = os.O_RDWR | os.O_CREAT

def __init__(self, keyspace, flags):
self.fd = os.open("{0}/{1}/keyspace".format(
settings.DIRNAME, keyspace
try:
os.mkdir(os.path.join(settings.DIRNAME, keyspace), 0o700)
except OSError as e:
pass
self.fd = os.open(os.path.join(
settings.DIRNAME, keyspace, "keyspace"
), os.O_RDONLY)

def __del__(self):
Expand Down
32 changes: 20 additions & 12 deletions countd/permanent/naive.py
Expand Up @@ -20,11 +20,11 @@ class Keyspace(abstract.Keyspace):

def __init__(self, keyspace, flags, index, deltas):
try:
os.mkdir("{0}/{1}".format(settings.DIRNAME, keyspace), 0o700)
except OSError:
os.mkdir(os.path.join(settings.DIRNAME, keyspace), 0o700)
except OSError as e:
pass
self.fd = os.open("{0}/{1}/keyspace".format(
settings.DIRNAME, keyspace
self.fd = os.open(os.path.join(
settings.DIRNAME, keyspace, "keyspace"
), flags, 0o600)
self.locks = locks.Locks()
self.index = index
Expand Down Expand Up @@ -150,13 +150,17 @@ class Index(abstract.Index):
LENGTH = settings.COUNT + settings.KEY
FORMAT = "<q{0}c".format(settings.KEYSPACE)

READ = os.O_RDONLY
READ = os.O_RDONLY | os.O_CREAT
WRITE = os.O_RDWR | os.O_CREAT

def __init__(self, keyspace, flags):
self.fd = os.open("{0}/{1}/keyspace".format(
settings.DIRNAME, keyspace
), os.O_RDONLY)
try:
os.mkdir(os.path.join(settings.DIRNAME, keyspace), 0o700)
except OSError as e:
pass
self.fd = os.open(os.path.join(
settings.DIRNAME, keyspace, "keyspace"
), self.READ, 0o600)

def __del__(self):
if hasattr(self, "fd"):
Expand Down Expand Up @@ -199,13 +203,17 @@ class Deltas(abstract.Deltas):
LENGTH = settings.COUNT + settings.KEY
FORMAT = "<q{0}c".format(settings.KEYSPACE)

READ = os.O_RDONLY
READ = os.O_RDONLY | os.O_CREAT
WRITE = os.O_RDWR | os.O_CREAT

def __init__(self, keyspace, flags):
self.fd = os.open("{0}/{1}/keyspace".format(
settings.DIRNAME, keyspace
), os.O_RDONLY)
try:
os.mkdir(os.path.join(settings.DIRNAME, keyspace), 0o700)
except OSError as e:
pass
self.fd = os.open(os.path.join(
settings.DIRNAME, keyspace, "keyspace"
), self.READ, 0o600)

def __del__(self):
if hasattr(self, "fd"):
Expand Down

0 comments on commit ff8484a

Please sign in to comment.