def tryReadLink(path):
    try:
        prevPath, initialPath = path, path
        readlinkCount, maxReadlinkCount = 0, 100
        while isLink(path):
            path = junction.readlink(path)
            if path == prevPath: # no idea if this can happen, but why risk it
                break
            # Prevent infinite loop if circular paths are present (A->B->C->A)
            readlinkCount = readlinkCount + 1
            if readlinkCount == maxReadlinkCount:
                return initialPath
            prevPath = path
        return path
    except:
        return None
Example #2
0
def tryReadLink(path):
    try:
        prevPath, initialPath = path, path
        readlinkCount, maxReadlinkCount = 0, 100
        while isLink(path):
            path = junction.readlink(path)
            if path == prevPath:  # no idea if this can happen, but why risk it
                break
            # Prevent infinite loop if circular paths are present (A->B->C->A)
            readlinkCount = readlinkCount + 1
            if readlinkCount == maxReadlinkCount:
                return initialPath
            prevPath = path
        return path
    except:
        return None
Example #3
0
    def test(self):
        link = 'junction'
        contents = 'bar'
        link_file = os.path.join(link, os.path.relpath(self.DIR_FILE, self.DIR))

        create(self.DIR, link)
        self.assertEqual(os.path.abspath(self.DIR), readlink(link))

        with open(link_file, 'r') as fd:
            self.assertEqual(fd.read(), self.DIR_FILE_CONTENTS)

        with open(self.DIR_FILE, 'w') as fd:
            fd.write(contents)

        with open(link_file, 'r') as fd:
            self.assertEqual(fd.read(), contents)

        unlink(link)
        self.assertFalse(os.path.exists(link))
Example #4
0
def tryReadLink(path):
    try:
        return junction.readlink(path)
    except:
        return None
Example #5
0
 def new_readlink(path):
     if os.path.isdir(path):
         return junction.readlink(path)
     return hardlink.readlink(path)
Example #6
0
def tryReadLink(path):
    try:
        return junction.readlink(path)
    except:
        return None