Exemplo n.º 1
0
    def test_soft_link(self):
        path1_real_file = join(self.test_dir, 'path1_real_file')
        path2_symlink = join(self.test_dir, 'path2_symlink')
        touch(path1_real_file)
        assert isfile(path1_real_file)
        assert not islink(path1_real_file)

        if not softlink_supported(path1_real_file, self.test_dir) and on_win:
            pytest.skip("softlink not supported")

        symlink(path1_real_file, path2_symlink)
        assert exists(path2_symlink)
        assert lexists(path2_symlink)
        assert islink(path2_symlink)

        assert readlink(path2_symlink).endswith(path1_real_file)
        # for win py27, readlink actually gives something that starts with \??\
        # \??\c:\users\appveyor\appdata\local\temp\1\c571cb0c\path1_real_file

        assert stat_nlink(path1_real_file) == stat_nlink(path2_symlink) == 1

        os.unlink(path1_real_file)
        assert not isfile(path1_real_file)
        assert not lexists(path1_real_file)
        assert not exists(path1_real_file)

        assert lexists(path2_symlink)
        if not (on_win and PY2):
            # I guess I'm not surprised this exist vs lexist is different for win py2
            #   consider adding a fix in the future
            assert not exists(path2_symlink)

        os.unlink(path2_symlink)
        assert not lexists(path2_symlink)
        assert not exists(path2_symlink)
Exemplo n.º 2
0
    def test_soft_link(self):
        path1_real_file = join(self.test_dir, 'path1_real_file')
        path2_symlink = join(self.test_dir, 'path2_symlink')
        touch(path1_real_file)
        assert isfile(path1_real_file)
        assert not islink(path1_real_file)

        if not softlink_supported(path1_real_file, self.test_dir) and on_win:
            pytest.skip("softlink not supported")

        symlink(path1_real_file, path2_symlink)
        assert exists(path2_symlink)
        assert lexists(path2_symlink)
        assert islink(path2_symlink)

        assert readlink(path2_symlink).endswith(path1_real_file)
        # Windows Python >3.7, readlink actually gives something that starts with \\?\
        # \\?\C:\users\appveyor\appdata\local\temp\1\c571cb0c\path1_real_file

        assert os.lstat(path1_real_file).st_nlink == os.lstat(
            path2_symlink).st_nlink == 1

        os.unlink(path1_real_file)
        assert not isfile(path1_real_file)
        assert not lexists(path1_real_file)
        assert not exists(path1_real_file)
        assert lexists(path2_symlink)
        assert not exists(path2_symlink)

        os.unlink(path2_symlink)
        assert not lexists(path2_symlink)
        assert not exists(path2_symlink)
Exemplo n.º 3
0
    def test_soft_link(self):
        path1_real_file = join(self.test_dir, 'path1_real_file')
        path2_symlink = join(self.test_dir, 'path2_symlink')
        touch(path1_real_file)
        assert isfile(path1_real_file)
        assert not islink(path1_real_file)

        symlink(path1_real_file, path2_symlink)
        assert exists(path2_symlink)
        assert lexists(path2_symlink)
        assert islink(path2_symlink)

        assert readlink(path2_symlink).endswith(path1_real_file)
        # for win py27, readlink actually gives something that starts with \??\
        # \??\c:\users\appveyor\appdata\local\temp\1\c571cb0c\path1_real_file

        assert stat_nlink(path1_real_file) == stat_nlink(path2_symlink) == 1

        os.unlink(path1_real_file)
        assert not isfile(path1_real_file)
        assert not lexists(path1_real_file)
        assert not exists(path1_real_file)

        assert lexists(path2_symlink)
        if not (on_win and PY2):
            # I guess I'm not surprised this exist vs lexist is different for win py2
            #   consider adding a fix in the future
            assert not exists(path2_symlink)

        os.unlink(path2_symlink)
        assert not lexists(path2_symlink)
        assert not exists(path2_symlink)
Exemplo n.º 4
0
def test_remove_link_to_dir(tmpdir):
    dst_link = join(text_type(tmpdir), "test_link")
    src_dir = join(text_type(tmpdir), "test_dir")
    tmpdir.mkdir("test_dir")
    os.symlink(src_dir, dst_link)
    assert isdir(src_dir)
    assert not islink(src_dir)
    assert islink(dst_link)
    assert rm_rf(dst_link) is True
    assert isdir(src_dir)  # make sure the directory is still there
    assert not isdir(dst_link)
    assert not lexists(dst_link)
Exemplo n.º 5
0
def test_remove_link_to_file(tmpdir):
    dst_link = join(text_type(tmpdir), "test_link")
    src_file = join(text_type(tmpdir), "test_file")
    _write_file(src_file, "welcome to the ministry of silly walks")
    os.symlink(src_file, dst_link)
    assert isfile(src_file)
    assert not islink(src_file)
    assert islink(dst_link)
    assert rm_rf(dst_link) is True
    assert isfile(src_file)  # make sure the directory is still there
    assert not isfile(dst_link)
    assert not lexists(dst_link)
Exemplo n.º 6
0
    def test_simple_LinkPathAction_copy(self):
        source_full_path = make_test_file(self.pkgs_dir)
        target_short_path = source_short_path = basename(source_full_path)

        correct_sha256 = compute_sha256sum(source_full_path)
        correct_size_in_bytes = getsize(source_full_path)
        path_type = PathType.hardlink

        source_path_data = PathDataV1(
            _path = source_short_path,
            path_type=path_type,
            sha256=correct_sha256,
            size_in_bytes=correct_size_in_bytes,
        )

        axn = LinkPathAction({}, None, self.pkgs_dir, source_short_path, self.prefix,
                             target_short_path, LinkType.copy, source_path_data)

        assert axn.target_full_path == join(self.prefix, target_short_path)
        axn.verify()
        axn.execute()
        assert isfile(axn.target_full_path)
        assert not islink(axn.target_full_path)
        assert stat_nlink(axn.target_full_path) == 1

        axn.reverse()
        assert not lexists(axn.target_full_path)
Exemplo n.º 7
0
    def test_simple_LinkPathAction_softlink(self):
        if not softlink_supported(__file__, self.prefix) and on_win:
            pytest.skip("softlink not supported")

        source_full_path = make_test_file(self.pkgs_dir)
        target_short_path = source_short_path = basename(source_full_path)

        correct_sha256 = compute_sha256sum(source_full_path)
        correct_size_in_bytes = getsize(source_full_path)
        path_type = PathType.hardlink

        source_path_data = PathDataV1(
            _path = source_short_path,
            path_type=path_type,
            sha256=correct_sha256,
            size_in_bytes=correct_size_in_bytes,
        )

        axn = LinkPathAction({}, None, self.pkgs_dir, source_short_path, self.prefix,
                             target_short_path, LinkType.softlink, source_path_data)

        assert axn.target_full_path == join(self.prefix, target_short_path)
        axn.verify()
        axn.execute()
        assert isfile(axn.target_full_path)
        assert islink(axn.target_full_path)
        assert stat_nlink(axn.target_full_path) == 1

        axn.reverse()
        assert not lexists(axn.target_full_path)
        assert lexists(source_full_path)
Exemplo n.º 8
0
    def test_simple_LinkPathAction_copy(self):
        source_full_path = make_test_file(self.pkgs_dir)
        target_short_path = source_short_path = basename(source_full_path)

        correct_sha256 = compute_sha256sum(source_full_path)
        correct_size_in_bytes = getsize(source_full_path)
        path_type = PathType.hardlink

        source_path_data = PathDataV1(
            _path = source_short_path,
            path_type=path_type,
            sha256=correct_sha256,
            size_in_bytes=correct_size_in_bytes,
        )

        axn = LinkPathAction({}, None, self.pkgs_dir, source_short_path, self.prefix,
                             target_short_path, LinkType.copy, source_path_data)

        assert axn.target_full_path == join(self.prefix, target_short_path)
        axn.verify()
        axn.execute()
        assert isfile(axn.target_full_path)
        assert not islink(axn.target_full_path)
        assert stat_nlink(axn.target_full_path) == 1

        axn.reverse()
        assert not lexists(axn.target_full_path)
Exemplo n.º 9
0
    def test_simple_LinkPathAction_softlink(self):
        if not softlink_supported(__file__, self.prefix) and on_win:
            pytest.skip("softlink not supported")

        source_full_path = make_test_file(self.pkgs_dir)
        target_short_path = source_short_path = basename(source_full_path)

        correct_sha256 = compute_sha256sum(source_full_path)
        correct_size_in_bytes = getsize(source_full_path)
        path_type = PathType.hardlink

        source_path_data = PathDataV1(
            _path = source_short_path,
            path_type=path_type,
            sha256=correct_sha256,
            size_in_bytes=correct_size_in_bytes,
        )

        axn = LinkPathAction({}, None, self.pkgs_dir, source_short_path, self.prefix,
                             target_short_path, LinkType.softlink, source_path_data)

        assert axn.target_full_path == join(self.prefix, target_short_path)
        axn.verify()
        axn.execute()
        assert isfile(axn.target_full_path)
        assert islink(axn.target_full_path)
        assert stat_nlink(axn.target_full_path) == 1

        axn.reverse()
        assert not lexists(axn.target_full_path)
        assert lexists(source_full_path)
Exemplo n.º 10
0
def test_remove_dir(tmpdir):
    test_dir = "test"
    tmpdir.mkdir(test_dir)
    path = join(text_type(tmpdir), test_dir)
    assert isdir(path)
    assert not islink(path)
    assert rm_rf(path) is True
    assert not isdir(path)
    assert not lexists(path)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
0
    def test_simple_LinkPathAction_copy(self):
        source_full_path = make_test_file(self.pkgs_dir)
        target_short_path = source_short_path = basename(source_full_path)
        axn = LinkPathAction({}, None, self.pkgs_dir, source_short_path,
                             self.prefix, target_short_path, LinkType.copy)

        assert axn.target_full_path == join(self.prefix, target_short_path)
        axn.verify()
        axn.execute()
        assert isfile(axn.target_full_path)
        assert not islink(axn.target_full_path)
        assert stat_nlink(axn.target_full_path) == 1

        axn.reverse()
        assert not lexists(axn.target_full_path)
Exemplo n.º 14
0
    def test_simple_LinkPathAction_copy(self):
        source_full_path = make_test_file(self.pkgs_dir)
        target_short_path = source_short_path = basename(source_full_path)
        axn = LinkPathAction({}, None, self.pkgs_dir, source_short_path, self.prefix,
                             target_short_path, LinkType.copy)

        assert axn.target_full_path == join(self.prefix, target_short_path)
        axn.verify()
        axn.execute()
        assert isfile(axn.target_full_path)
        assert not islink(axn.target_full_path)
        assert stat_nlink(axn.target_full_path) == 1

        axn.reverse()
        assert not lexists(axn.target_full_path)