Beispiel #1
0
def test_lexists_broken_symlink(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    symlink(src_filename, dst_filename)

    assert lexists(dst_filename) is True
Beispiel #2
0
def test_islink_with_broken_dir_link(smb_share):
    src_dir_name = "%s\\dir" % smb_share
    dst_dir_name = "%s\\link" % smb_share

    symlink(src_dir_name, dst_dir_name, target_is_directory=True)

    assert islink(dst_dir_name) is True
Beispiel #3
0
def test_islink_with_broken_file_link(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    symlink(src_filename, dst_filename)

    assert islink(dst_filename) is True
Beispiel #4
0
def test_islink_with_dir_link(smb_share):
    src_dir_name = "%s\\dir" % smb_share
    dst_dir_name = "%s\\link" % smb_share

    mkdir(src_dir_name)
    symlink(src_dir_name, dst_dir_name)

    assert islink(dst_dir_name) is True
Beispiel #5
0
def test_samefile_with_broken_symlink(smb_share):
    file1 = "%s\\file1.txt" % smb_share
    file2 = "%s\\file2.txt" % smb_share

    symlink(file1, file2)

    expected = "[NtStatus 0xc0000034] No such file or directory: "
    with pytest.raises(OSError, match=re.escape(expected)):
        samefile(file1, file2)
Beispiel #6
0
def test_islink_with_file_link(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    with open_file(src_filename, mode='w') as fd:
        fd.write(u"content")
    symlink(src_filename, dst_filename)

    assert islink(dst_filename) is True
Beispiel #7
0
def test_exists_working_symlink(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    with open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    symlink(src_filename, dst_filename)

    assert exists(dst_filename) is True
Beispiel #8
0
def test_samefile_with_symlink(smb_share):
    file1 = "%s\\file1.txt" % smb_share
    file2 = "%s\\file2.txt" % smb_share

    with open_file(file1, mode='w') as fd:
        fd.write(u"content")

    symlink(file1, file2)

    assert samefile(file1, file2) is True
Beispiel #9
0
 def symlink(self, src, dst, target_is_directory=False):
     return smbclient.symlink(
         self._join_path(src),
         self._join_path(dst),
         target_is_directory=target_is_directory,
         **self._conn_kwargs,
     )
# Optional - register the server with explicit credentials
register_session("server", username="******", password="******")

# Read an existing file as text (credentials only needed for the first request to the server if not registered.)
with open_file(r"\\server\share\file.txt", username="******", password="******") as fd:
    file_contents = fd.read()

# Read an existing file as bytes
with open_file(r"\\server\share\file.txt", mode="rb") as fd:
    file_bytes = fd.read()

# Create a file and write to it
with open_file(r"\\server\share\file.txt", mode="w") as fd:
    fd.write(u"content")

# Write data to the end of an existing file
with open_file(r"\\server\share\file.txt", mode="a") as fd:
    fd.write(u"\ndata at the end")

# Delete a file
remove(r"\\server\share\file.txt")

# Get info about a file
stat(r"\\server\share\file.txt")

# Create a symbolic link
symlink(r"\\server\share\directory", r"\\server\share\link")

# Create a hard link
link(r"\\server\share\file.txt", r"\\server\share\hard-link.txt")