smb2_rename move files to a non-root directory failed.
If "smb moves a file from a non-root directory tmp to dst" is needed, what should I do? The api is: int smb2_rename(struct smb2_context *smb2, const char *oldpath, const char *newpath) Environment: directories are in Windows10, project running in Redhat 8. Problem: I created 2 directories -- "tmp" and "dst" -- in the root directory, and transfered a file "test.txt" to the "tmp" successfully. Then I mv "test.txt" to directory "dst" ended with failure. What confused me is, when I tried to mv "test.txt" to root, it worked. This shows how I use the api(smb2_connect_share was established with the smb2_context *smb2).
- mv "test.txt" to directory "dst":
char *oldpath = "tmp/test.txt";
char *newpath = "dst/test.txt";
int ret = 0;
ret = smb2_rename(smb2, oldpath, newpath);
**It failed with STATUS_OBJECT_NAME_NOT_FOUND.**
2.mv "test.txt" to root:
char *oldpath = "tmp/test.txt";
char *newpath = "test.txt";
int ret = 0;
ret = smb2_rename(smb2, oldpath, newpath);
**Now in the root directory, there are 2 directories and 1 text file.**
After I learned the definition of smb2_rename_async, I found the code fragment:
/* CREATE command */
(other codes)
cr_req.name = olapath;
(other codes)
/* SET INFO command */
rn_info.replace_if_exist = 0;
rn_info.file_name = discard_const(newpath);
`` I have limited knowledge of protocol smb, so it may be silly that I conjecture that in smb2_rename_async, the parameter newpath meant the file's name and it always mv the file to the root directory, rather than the full path, which differed from oldpath. In this case, when I tried to mv test.txt from directory tmp to dst, the system sought to mv test.txt to root and rename the file with dst/test.txt actually. Therefore, if "smb moves a file from a non-root directory tmp to dst" is needed, what should I do?
All the paths should be relative to the root of the share if I recall correctly.
Please try current master, it has an example utility that uses smb2_rename()
On my server, I created two directories src and dst and in src I created a file called hello. I then run : ./examples/smb2-rename-sync smb://[email protected]/PS2SMB/ src/hello dst/hello and it renames / moves the file to dst/hello
Can you try that?
All the paths should be relative to the root of the share if I recall correctly.
Please try current master, it has an example utility that uses smb2_rename()
On my server, I created two directories src and dst and in src I created a file called hello. I then run : ./examples/smb2-rename-sync smb://[email protected]/PS2SMB/ src/hello dst/hello and it renames / moves the file to dst/hello
Can you try that?
Thank you. I've tried and it still failed. Possibly it conflicts with my security engine(cannot be removed). For example, using smb2_mkdir() to create a directory that already exists should return STATUS_OBJECT_NAME_COLLISION or what, but smb2_get_error() got NULL. In fact in my project it got nothing except STATUS_INVALID_PARAMETER while the wireshark could always capture them.
@sahlberg I'm also facing an issue with rename. I rename a file in the same directory.
example: Rename from "testfolder/testfile.txt" to "testfolder/rename.txt" and is fails. smb2_get_error returns an empty string. Return code = -5
Edit: After more testing, this is only a problem with Windows shares in Win 7/10 and 11. Samba on Linux doesn't have this problem. Edit1: Also using the samba "smbclient" tool, it's able to rename files in subfolders in Windows Shares. Edit2: I compiled the "smb2-rename-sync.c program in Ubuntu and it also fails to rename files in subdirectories for Windows Shares.
I have pushed a fix for this to the master branch now. Thanks for the report.