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

Improved "rename" support #26

Open
aktau opened this issue Jul 8, 2014 · 13 comments
Open

Improved "rename" support #26

aktau opened this issue Jul 8, 2014 · 13 comments
Labels

Comments

@aktau
Copy link

aktau commented Jul 8, 2014

As mentioned here: howeyc/fsnotify#104

Currently, it's not straightforward to detect a rename correctly. In most cases, one will see this:

RENAME file1
CREATE file2

Yet this doesn't guarantee that file1 and file2 are the same file (there could be a file creation in between, or file1 could be moved outside a watched folder and file2 could be moved in). To work around this, one could store the os.FileInfo for every watched file and use os.SameFile to compare it with the new file. This is a bit cumbersome though, as it requires keeping a lot of os.FileInfo structs in memory + bookkeeping them.

However, some platforms provide a way to atomically see what was the old name and what's the new name of a file. To quote @nathany:

On Linux there is a "cookie" used to tie the RENAME FROM and TO events together, but this isn't currently exposed by fsnotify. I still need to do more research across each platform.

This is a tracker issue to see if there is sufficient cross-platform support to enable this in the default API.

@kars7e

This comment was marked as spam.

@jaytaylor

This comment was marked as spam.

@nathany

This comment was marked as outdated.

@jmhodges

This comment was marked as spam.

@jmhodges
Copy link

jmhodges commented May 4, 2015

I think watchdog (https://github.com/gorakhargosh/watchdog) has figured out a cross-platform API, by the way.

@nathany
Copy link
Contributor

nathany commented May 13, 2015

@jmhodges Do you have any more details on "Weird Things" vim does? Is this when saving or is there a rename file function people are using in Vim?

@nathany
Copy link
Contributor

nathany commented May 20, 2015

ref: rjeczalik/notify#78

@omeid
Copy link

omeid commented May 23, 2015

Vim uses swap and backup files, involves rename and moving.

@F21

This comment was marked as spam.

@nathany

This comment was marked as outdated.

@F21
Copy link

F21 commented Feb 25, 2016

Do you think keeping a list of os.FileInfos in a concurrently safe map like map[string]*os.FileInfo as mentioned by @aktau is probably the best way to get this implemented?

@F21
Copy link

F21 commented Feb 29, 2016

Having done some experimentation on Windows, the os.Samefile() method doesn't work on Windows, because it compares by using the file path. So, if you had test.txt, the fileInfo stores the path to test.txt. After renaming it to test2.txt, using os.Lstat() on the new file stores the path as test2.txt. When you do a comparison with os.Samefile(), it sees that the file paths for the 2 FileInfos are different and returns false.

@Sprlia

This comment was marked as spam.

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

9 participants