Browse Source

make path absolute, so same dir/file from different cwd are same

main
John-Mark Gurney 2 years ago
parent
commit
ff565c7b93
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      ui/medashare/cli.py

+ 9
- 0
ui/medashare/cli.py View File

@@ -548,7 +548,9 @@ class FileObject(MDBase):

@classmethod
def from_file(cls, filename, created_by_ref):
filename = os.path.abspath(filename)
s = os.stat(filename)
# XXX - race here, fix w/ checking mtime before/after?
obj = {
'created_by_ref': created_by_ref,
'hostid': hostuuid(),
@@ -840,6 +842,13 @@ class _TestCases(unittest.TestCase):

self.oldcwd = os.getcwd()

def test_fileobject_abs(self):
os.chdir(self.tempdir)

a = FileObject.from_file('test.txt', self.created_by_ref)

self.assertEqual(a.dir[0], '/')

def tearDown(self):
shutil.rmtree(self.basetempdir)
self.tempdir = None


Loading…
Cancel
Save