示例#1
0
    def test_hard_link(self):
        path1_real_file = join(self.test_dir, 'path1_real_file')
        path2_second_inode = join(self.test_dir, 'path2_second_inode')
        touch(path1_real_file)
        assert isfile(path1_real_file)
        assert not islink(path1_real_file)
        link(path1_real_file, path2_second_inode)
        assert isfile(path2_second_inode)
        assert not islink(path2_second_inode)

        path1_stat = os.lstat(path1_real_file)
        path2_stat = os.lstat(path2_second_inode)
        assert path1_stat.st_ino == path2_stat.st_ino
        assert path1_stat.st_nlink == path2_stat.st_nlink

        os.unlink(path2_second_inode)
        assert not lexists(path2_second_inode)
        assert os.lstat(path1_real_file).st_nlink == 1

        os.unlink(path1_real_file)
        assert not lexists(path1_real_file)
示例#2
0
    def test_hard_link(self):
        path1_real_file = join(self.test_dir, 'path1_real_file')
        path2_second_inode = join(self.test_dir, 'path2_second_inode')
        touch(path1_real_file)
        assert isfile(path1_real_file)
        assert not islink(path1_real_file)
        link(path1_real_file, path2_second_inode)
        assert isfile(path2_second_inode)
        assert not islink(path2_second_inode)

        path1_stat = os.stat(path1_real_file)
        path2_stat = os.stat(path2_second_inode)

        assert path1_stat.st_ino == path2_stat.st_ino
        assert stat_nlink(path1_real_file) == stat_nlink(path2_second_inode)

        os.unlink(path2_second_inode)
        assert not lexists(path2_second_inode)
        assert stat_nlink(path1_real_file) == 1

        os.unlink(path1_real_file)
        assert not lexists(path1_real_file)
示例#3
0
def _get_temp_prefix(name=None, use_restricted_unicode=False):
    tmpdir = tmpdir_in_use or gettempdir()
    capable = running_a_python_capable_of_unicode_subprocessing()

    if not capable or use_restricted_unicode:
        RESTRICTED = UNICODE_CHARACTERS_RESTRICTED
        random_unicode = "".join(sample(RESTRICTED, len(RESTRICTED)))
    else:
        random_unicode = "".join(
            sample(UNICODE_CHARACTERS, len(UNICODE_CHARACTERS)))
    tmpdir_name = os.environ.get(
        "CONDA_TEST_TMPDIR_NAME",
        (str(uuid4())[:4] + SPACER_CHARACTER +
         random_unicode) if name is None else name,
    )
    prefix = join(tmpdir, tmpdir_name)

    # Exit immediately if we cannot use hardlinks, on Windows, we get permissions errors if we use
    # sys.executable so instead use the pdb files.
    src = sys.executable.replace(".exe", ".pdb") if on_win else sys.executable
    dst = os.path.join(tmpdir, os.path.basename(sys.executable))

    try:
        link(src, dst)
    except (IOError, OSError):
        print(
            "\nWARNING :: You are testing `conda` with `tmpdir`:-\n           {}\n"
            "           not on the same FS as `sys.prefix`:\n           {}\n"
            "           this will be slow and unlike the majority of end-user installs.\n"
            "           Please pass `--basetemp=<somewhere-else>` instead.".
            format(tmpdir, sys.prefix))
    try:
        rm_rf(dst)
    except Exception as e:
        print(e)
        pass

    return prefix