Skip to content

Commit

Permalink
Fix Issue #231.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlinford committed Nov 12, 2017
1 parent 4c8d103 commit c8c3c86
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/taucmdr/cf/storage/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import os
import json
import tinydb
import tempfile
from tinydb import operations
from taucmdr import logger, util
from taucmdr.error import ConfigurationError
Expand Down Expand Up @@ -140,9 +141,23 @@ def iteritems(self):
yield item['key'], item['value']

def is_writable(self):
"""Check if the storage filesystem is writable."""
"""Check if the storage filesystem is writable.
Attempts to create and delete a file in ``prefix``.
See https://github.com/ParaToolsInc/taucmdr/issues/231.
Returns:
bool: True if a file could be created and deleted in ``prefix``, False otherwise.
"""
self.connect_filesystem()
return os.access(self.prefix, os.W_OK)
if not os.access(self.prefix, os.W_OK):
return False
try:
with tempfile.NamedTemporaryFile(dir=self.prefix, delete=True) as tmp_file:
tmp_file.write("Write test. Delete this file.")
except (OSError, IOError):
return False
return True

def connect_filesystem(self, *args, **kwargs):
"""Prepares the store filesystem for reading and writing."""
Expand Down

0 comments on commit c8c3c86

Please sign in to comment.