Skip to content

Commit

Permalink
Merge PR #24578 into master
Browse files Browse the repository at this point in the history
* refs/pull/24578/head:
	pybind/ceph_argparse.py: do not create file for validating CephFilepath

Reviewed-by: Brad Hubbard <bhubbard@redhat.com>
Reviewed-by: Neha Ojha <nojha@redhat.com>
  • Loading branch information
liewegas committed Oct 16, 2018
2 parents 862dd21 + 90c2c28 commit 369a272
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/pybind/ceph_argparse.py
Expand Up @@ -501,13 +501,24 @@ class CephFilepath(CephArgtype):
Openable file
"""
def valid(self, s, partial=False):
try:
f = open(s, 'a+')
except Exception as e:
raise ArgumentValid('can\'t open {0}: {1}'.format(s, e))
f.close()
# set self.val if the specified path is readable or writable
s = os.path.abspath(s)
if not os.access(s, os.R_OK):
self._validate_writable_file(s)
self.val = s

def _validate_writable_file(self, fname):
if os.path.exists(fname):
if os.path.isfile(fname):
if not os.access(fname, os.W_OK):
raise ArgumentValid('{0} is not writable'.format(fname))
else:
raise ArgumentValid('{0} is not file'.format(fname))
else:
dirname = os.path.dirname(fname)
if not os.access(dirname, os.W_OK):
raise ArgumentValid('cannot create file in {0}'.format(dirname))

def __str__(self):
return '<outfilename>'

Expand Down

0 comments on commit 369a272

Please sign in to comment.