Read-only FS detection
Hi, I have few deps that by default create cache/log dirs... I can disable it, but the detection itself is unclear.
Is there a better way than
2 Replies
The documentation suggests that your approach is generally correct. However, it's important to note that you should be careful with the error handling. In your current setup, you're catching all errors and assuming they mean the file system is read-only. However, other errors could occur, such as
Deno.errors.PermissionDenied if you don't have the --allow-write flag, or Deno.errors.AlreadyExists if the directory already exists.
Here's a more precise way to check if the file system is read-only:
This code will return false if the PermissionDenied error is thrown, indicating that the file system is read-only. If any other error is thrown, it will be rethrown, allowing you to handle it elsewhere in your code.
Remember to run your script with the --unstable and --allow-write flags, as the Deno.mkdirSync function requires write permissions. 🦕Actually that's smart