Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can it surpport POSIX rename interface now #254

Closed
oucaijun opened this issue Dec 7, 2020 · 3 comments
Closed

can it surpport POSIX rename interface now #254

oucaijun opened this issue Dec 7, 2020 · 3 comments

Comments

@oucaijun
Copy link

oucaijun commented Dec 7, 2020

Hi,
I am choosing aft-mtp-mount to mount my devices as a result of it's amazing speed to read/write/dir iterator.

I used QFile::rename (from Qt) to rename a file or a directory and failed! Hope to have rename API because it's a frequently used function.

step1: mount mobile with path /home/ocean/my-device/ (with mobile file transfer mode set)

$ fuse/aft-mtp-mount /home/ocean//my-device

step2: prepare an empty directory under mobile path.
mkdir -p /home/ocean//my-device/nulldfrom

step2: run the demo.
./t_rename

step3: the debug info shown us "rename nulldfrom to nulldto"

//Returns true if successful; otherwise returns false.
bool qtRename()
{
    QString src =  "nulldfrom";
    QString dest =  "nulldto";

    QString mtpDirPath = "/home/ocean/my-device/内部存储/Test";
    int status = chdir(mtpDirPath.toStdString().c_str());
    QString statusinfo = (status==0 )? "ok" : "error";
    qDebug()<<"-------- chdir " << mtpDirPath << " status ="<< statusinfo;

    //TEST QFile::rename()
    QFile from(src);
    bool ret = from.rename(dest); // failed

    //Print rename status info
    statusinfo = (ret==true )? "ok" : "error";
    qDebug()<<"-------- rename"<< src << " to "<< dest <<", status ="<< statusinfo;

    return ret;
}

I also used std::ename with the same result!

//TEST std::rename()
ret = std::rename(src.toStdString().c_str(), dest.toStdString().c_str());
ret = (ret == 0)?true:false;

//Print rename status info
statusinfo = (ret==true )? "ok" : "error";
qDebug()<<"-------- rename"<< src << " to "<< dest <<", status ="<< statusinfo;

@oucaijun oucaijun changed the title can you surpport POSIX rename interface now can it surpport POSIX rename interface now Dec 7, 2020
@whoozle
Copy link
Owner

whoozle commented Dec 7, 2020

Unfortunately there's a few reasons for that:

  1. I haven't seen any single android device that supports renaming in POSIX sense (e.g. setting completely new path, moving around filesystem, etc)
  2. POSIX rename will not rename across filesystem boundary, so it does not always work too. Userland tools rely on error code EXDEV and do safe copy/unlink.
       EXDEV       The links named by new and old are on different file systems and the implementation does not support  links  between  file
                   systems.

So I return EXDEV to signal that copy/unlink required.

I can explore the possibility of setting "filename" property(if and only, source/destination paths are in the same directory), but I think I've tried it before and it didn't work.

@oucaijun
Copy link
Author

oucaijun commented Dec 7, 2020

Yes, I totally approval of a limitted support to rename(limit with "/", limit with directory, limit with soft link, etc). In the case of mobile devices, we can't really demand the complete rename function.

Especially in appications like filemanager, most of the renaming takes place under the same folder. If the user uses an operation that is not supported by fuse rename, it is not too late to return an error.

I know you must have implemented the rename function and I willing to try the function.

@whoozle
Copy link
Owner

whoozle commented Dec 12, 2020

fixed in 140beb4

@whoozle whoozle closed this as completed Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants