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

The MTP responder side renames the file, but the MTP Initiator side does not update it #53

Closed
woshizhy opened this issue Dec 29, 2020 · 4 comments

Comments

@woshizhy
Copy link
Contributor

Hello.

As shown in the title, I found that MTP responder did not listen for rename events. (for example: mv hello.c hello.java)
(Only the events of adding/modifying and deleting files are monitored for your uMTP-Responder)

So when renaming a file on the MTP responder side, no event occurred, and no event was reported to MTP Initiator .

If want to support this function( renames the file on the MTP responder side, and the MTP Initiator also can update)
I find it possible to do this:

  1. Add events to listen for renamed files: (modify file: src/inotify.c )
int inotify_handler_addwatch( mtp_ctx * ctx, char * path )
 {
...
            if ( !ctx->no_inotify )
            {
--                   return inotify_add_watch( ctx->inotify_fd, path, IN_CREATE | IN_DELETE | IN_MODIFY );
++                 return inotify_add_watch( ctx->inotify_fd, path, IN_CREATE | IN_DELETE | IN_MODIFY | 
++                                                                                            IN_MOVED_FROM |  IN_MOVED_TO );
            }
...
 }
  1. Handling events: (modify file: src/inotify.c )
void *inotify_gotsig(int sig, siginfo_t *info, void *ucontext)
{
...
--              if ( event->mask & IN_CREATE )
++            if ( event->mask & IN_CREATE || event->mask & IN_MOVED_TO )
      
--              if ( event->mask & IN_DELETE )
++            if ( event->mask & IN_DELETE || event->mask & IN_MOVED_FROM )
...
 }

And I I tested it and it worked.
(The MTP Initiator tested are: win7 and win 10)

But I just passed the preliminary verification, and I don't know if there are any bugs.

Do you argee?

Thanks, I wish you a happy life.

@jfdelnero
Copy link
Member

Yes this appears fine to me.
Please make a pull request for this one too.
Thanks !

@jfdelnero
Copy link
Member

I have just tested the modification.
Please note that there was a mistake in the patch (IN_CREATE used instead of IN_DELETE in the delete case).
This is now fixed and all appears to work fine.
Thanks !

@woshizhy
Copy link
Contributor Author

woshizhy commented Jan 4, 2021

Oh, I'm sorry I didn't handle it.

Thank you for wiping my ass. ☺

@huangjie18
Copy link

Oh, It's very useful to me. Thank you for solving the problem. @woshizhy

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

3 participants