예제 #1
0
    def test(self):
        ret = main(["config", "cache.type", "symlink"])
        self.assertEqual(ret, 0)

        ret = main(["add", self.FOO])
        self.assertEqual(ret, 0)

        ret = main(["add", self.DATA_DIR])
        self.assertEqual(ret, 0)

        if os.name == "nt":
            from jaraco.windows.filesystem import readlink
        else:
            readlink = os.readlink

        self.assertTrue(System.is_symlink(self.FOO))
        old_foo_link = readlink(self.FOO)

        self.assertTrue(System.is_symlink(self.DATA))
        old_data_link = readlink(self.DATA)

        old_cache_dir = self.dvc.cache.local.cache_dir
        new_cache_dir = old_cache_dir + "_new"
        os.rename(old_cache_dir, new_cache_dir)

        ret = main(["cache", "dir", new_cache_dir])
        self.assertEqual(ret, 0)

        ret = main(["checkout", "-f"])
        self.assertEqual(ret, 0)

        self.assertTrue(System.is_symlink(self.FOO))
        new_foo_link = readlink(self.FOO)

        self.assertTrue(System.is_symlink(self.DATA))
        new_data_link = readlink(self.DATA)

        self.assertEqual(
            os.path.relpath(old_foo_link, old_cache_dir),
            os.path.relpath(new_foo_link, new_cache_dir),
        )

        self.assertEqual(
            os.path.relpath(old_data_link, old_cache_dir),
            os.path.relpath(new_data_link, new_cache_dir),
        )
예제 #2
0
 def isfile(self, path, start=None):
     """Return True if path is an existing regular file.
     This follows symbolic links, so both islink() and isfile() can be true for the same path.
     """
     if self.islink(path):
         if not start:
             start = os.path.abspath('.')
         path = os.path.join(start, fs.readlink(path))
     return os.path.isfile(path)
예제 #3
0
def replace_links(link, max_depth=10):
    link_depth = 0
    target = link

    for attempt in range(0, max_depth):
        if not islink(target):
            break
        target = readlink(target)
        link_depth = attempt

    if not link_depth:
        logger.debug('{0} is not a link'.format(link))
    elif link_depth > max_depth or (link_depth == max_depth and islink(target)):
        logger.warning('Exceeded maximum depth {0} while following link {1}'.format(max_depth, link))
    else:
        logger.info('Changing sym-link: {0} to point directly to file: {1}'.format(link, target), 'COPYLINK')
        os.unlink(link)
        linktastic.symlink(target, link)
예제 #4
0
 def readlink(self, path):
     return fs.readlink(path)