socketsupply / socket

A cross-platform runtime for Web developers to build desktop & mobile apps for any OS using any frontend library.
https://socketsupply.co/guides
Other
1.6k stars 75 forks source link

fs.watch() strips backslash directory separators for filenames/paths on Windows #940

Open WolfBearGames opened 6 months ago

WolfBearGames commented 6 months ago

What OS are you using (uname -a, or Windows version)?

Windows 11

What version Socket Runtime are you using?

0.5.4 (f90ba121)

What did you expect to see and what you saw instead?

I'm using fs.watch() to watch a directory and its sub directories for changes. I expect to receive events for changes with the respected path in the event:

{ eventType: 'rename', filename: 'PuzzleNotes\SubTestPuzzle\Textdokument (neu).txt' }

instead, I get this:

{ eventType: 'rename', filename: 'PuzzleNotesSubTestPuzzleTextdokument (neu).txt' }

The directory separators are missing. I did not test on any other platform then Windows, but I could imagine the the \ (backslashes) are being stripped somethere in the ipc communication.

WolfBearGames commented 6 months ago

This could be another issue, but there are more problems with fs watch on Windows:

  1. renaming a file sometimes causes a "SyntaxError: Bad control character in string literal in JSON" (probably also because of backslash problems)
  2. deleting a file in Windows Explorer sometimes does not trigger any change event.
  3. the returned path for changes in subfolders sometimes is incomplete.

As a suggestion: Is it possible to handle all the slash/backslash path "mess" in the socket API so that paths ALWAYS use forward slashes, even on Windows (and all Socket fs/path methods return paths with forward slashes)? I tried converting the windows path to a "normal" path with slashes, but some methods like "path.join" re-introduce backslashes into the resulting path.