SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.
Other
662 stars 101 forks source link

Support Windows long path aware #152

Closed solarispika closed 1 year ago

solarispika commented 1 year ago

I have a problem on watching directory whose path length is long. I have enabled longPathAware setting on Windows and add app manifest to enable it too. When there is a file unde the directory is updated, my UpdateListener::handleFileAction receives empty filename.

It looks like in this function https://github.com/SpartanJ/efsw/blob/23f6038879bdb2223ddebc6459618593565345e8/src/efsw/WatcherWin32.cpp#L9 WideCharToMultiByte() is using buffer of size MAX_PATH, which is 260, smaller than the path's. In my case it is 1028. Also it does not check the return code of 0, which indicates an error, therefore the filename is empty due to length being 0 from the return code.

SpartanJ commented 1 year ago

Oh, that code is very old, I never encountered the issue so I forgot about it. Let's fix it!

SpartanJ commented 1 year ago

@solarispika let me know if this works for you. I couldn't enable long paths, even following this, I expected at least that the file explorer worked with long paths to create a long path but it keeps complaining about the path length when I want to create it, so please confirm me if this works. The implementation now does not limit the number of bytes to assign, so it shouldn't have any problem.

solarispika commented 1 year ago

Hi @SpartanJ,

I have tested your work and it works as expected. Thanks!

As far as I know, Windows explorer doesn't support long paths due to compatibility reasons. However, you can try using PowerShell, with which you can create long path files.

SpartanJ commented 1 year ago

Great! Thanks for letting me know!