开发者

HTML5 FileSystem API: Can't use getFile() if file was deleted outside the API

开发者 https://www.devze.com 2023-03-28 09:46 出处:网络
I\'m using the HTML5 FileSystem API in a Chrome extension. There\'s an unlikely (but possible) scenario where:

I'm using the HTML5 FileSystem API in a Chrome extension.

There's an unlikely (but possible) scenario where:

  1. A file is created using fileWriter.write()
  2. User navigates to their Chrome User Data folder > File System folder, and deletes the file that was created (using their operating system,开发者_StackOverflow社区 not using the FileSystem API)
  3. All future calls of getFile() for this file trigger FileError.NOT_FOUND_ERR in the error handler.

It seems that if a file is deleted outside of the FileSystem API, getFile() always errors for that file, which prevents any success callback function from working, meaning I can't use fileEntry.remove(), nor fileEntry.createWriter() to create a new file with the same name.

Is there an alternate way to remove the file entry from the FileSystem's logic index?


There's a strange behaviour in Windows for Chrome apps/extensions. The fact is that if you delete the file manually from the app's filesystem directory, you won't be able to create a new one with the same name.

The only workaround right now is to create some kind of home directory hash when you app is called for the first time. Then you should write its name to (say) Local Storage and write your files to this directory. Your hash must be unique enough. In my case it is current date object timestamp. So when users delete and install your app/extension again, they won't be faced with this problem.

This refers to Windows systems only. Linux OS (and ChromeOS of course) doesn't have this bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消