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

Event path don't get updated if the parent directory is renamed. #119

Open
nohupped opened this issue Apr 30, 2017 · 2 comments
Open

Event path don't get updated if the parent directory is renamed. #119

nohupped opened this issue Apr 30, 2017 · 2 comments
Labels

Comments

@nohupped
Copy link

Apologies if I missed a way to get around this, and I am not sure if this is the expected behaviour either, but when there is a watcher created for a parent directory for eg: /tmp/testdirectory, and if I moved the parent directory itself as /tmp/moved, any events inside /tmp/moved will be shown as /tmp/directory/, which is the old path.

Code:

package main

import (
        "fmt"
        "github.com/rjeczalik/notify"
)

func main() {
        c := make(chan notify.EventInfo, 1)
        notify.Watch("/tmp/directory", c, notify.InCloseWrite, notify.Create, notify.InMovedFrom, notify.InMovedTo, notify.InCreate, notify.InDelete, notify.InCloseNowrite, notify.InModify)
        defer notify.Stop(c)
        for {
                switch ei := <-c; ei.Event() {
                default:
                        fmt.Println("Event is", ei.Path(), ei)
                }
        }
}

Output:
Console:

mkdir /tmp/directory/newdir

Daemon output:

Event is /tmp/directory notify.InCloseNowrite: "/tmp/directory"
Event is /tmp/directory notify.InCloseNowrite: "/tmp/directory"
Event is /tmp/directory/newdir notify.InCreate: "/tmp/directory/newdir"
Event is /tmp/directory/newdir notify.Create: "/tmp/directory/newdir"

Console:

mv /tmp/directory /tmp/moved
mkdir /tmp/moved/anotherdir

Daemon output:

Event is /tmp/directory/anotherdir notify.InCreate: "/tmp/directory/anotherdir"
Event is /tmp/directory/anotherdir notify.Create: "/tmp/directory/anotherdir"
Event is /tmp/directory notify.InCloseNowrite: "/tmp/directory"
Event is /tmp/directory/anotherdir notify.InCloseNowrite: "/tmp/directory/anotherdir"

(Shown as notify.InCreate: "/tmp/directory/anotherdir instead of notify.InCreate: "/tmp/moved/anotherdir" )
Is there any way when the parent directory is moved, it can reflect in the event's path with the updated directory name of the parent directory?

@ppknap
Copy link
Collaborator

ppknap commented May 10, 2017

Hey @nohupped , this is a bug in notify logic. Since inotify sends only file names, we store full paths in memory. However, when directory is moved, these paths are not updated.

Probably, we need to catch IN_MOVE_SELF events and update in-memory paths afterwards.

Note, that moving watched directories is generally not cross-platform - it is not possible to implement this correctly on Windows.

@ppknap ppknap added the bug label May 10, 2017
@madding
Copy link

madding commented Nov 10, 2018

Hi @ppknap! I try to do this task, but it impossible. I add IN_MOVE_SELF to InotifyAddWatch and I caught it, but I can't get new name of folder.

  1. IN_MOVE_SELF don't trigger IN_MOVE_TO.
  2. We have only file description and when I try run os.Readlink for /proc/self/fd/XXX it returned only anon_inode:inotify

No way to fix it. Good solution here it drop PANIC, but it breaks current workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants