Skip to content

Commit bcc385f

Browse files
committed
Handle Unwritable Path
1 parent 05f0d90 commit bcc385f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

filelock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _acquire(self):
347347
try:
348348
fd = os.open(self._lock_file, open_mode)
349349
except OSError:
350-
pass
350+
raise
351351
else:
352352
try:
353353
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)

test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,28 @@ class FileLockTest(BaseTest, unittest.TestCase):
366366

367367
LOCK_TYPE = filelock.FileLock
368368
LOCK_PATH = "test.lock"
369+
LOCK_PATH_UNWRITABLE = "test.lock.unwritable"
370+
371+
@classmethod
372+
def setUpClass(cls):
373+
try:
374+
os.mkdir(cls.LOCK_PATH_UNWRITABLE, 0)
375+
except:
376+
cls.fail("Could not create unwritable directory")
377+
378+
def test_write_fail(self):
379+
"""Ensures graceful failure of lock when path not writable."""
380+
lock1 = self.LOCK_TYPE("{}/test".format(self.LOCK_PATH_UNWRITABLE))
381+
with self.assertRaises(OSError):
382+
lock1.acquire()
383+
384+
@classmethod
385+
def tearDownClass(cls):
386+
"""Clean up."""
387+
try:
388+
os.rmdir(cls.LOCK_PATH_UNWRITABLE)
389+
except:
390+
pass
369391

370392

371393
class SoftFileLockTest(BaseTest, unittest.TestCase):

0 commit comments

Comments
 (0)