apache / apache/cordova-plugin-file
Directory read returns broken FileEntry objects
- Ngôn ngữ chính
- JavaScript
- Star
- 744
- Fork
- 754
- Merge trung bình
- 3 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 1
Mô tả
# Bug Report
## Problem
### What is expected to happen?
I should be able to read a FileEntry's metadata no matter how I got hold of the object
### What does actually happen?
I retrieving the FileEntry handle directly via `resolveLocalFilesystemURL` I can call getMetadata() on the returned object without an issue; but if I obtain the handle by reading the parent (root) directory, the call will result in NOT_FOUND_ERR`
### Command or Code
I am running the below code in the `deviceready` event handler:
```
console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
function errorHandler(e) {
console.error("Error: ", e);
}
function testFileMetadataRead() {
console.log("Successful file write...");
window.resolveLocalFileSystemURL(cordova.file.dataDirectory + "/test.txt", function(file) {
console.log("Contructor of FILE handle", file.constructor);
file.getMetadata(
function (m) { console.log("Getting FILE metadata", file, m) },
function (e) { console.log("Error getting FILE metadata", e) }
);
}, errorHandler);
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
dir.createReader().readEntries(function (entries) {
entries.forEach(function(entry) {
console.log("Contructor of DIRECTORY ENTRY handle", entry.constructor);
entry.getMetadata(
function (m) { console.log("Getting DIR ENTRY metadata", file, m) },
function (e) { console.log("Error getting DIR ENTRY metadata", e) }
);
});
}, function (e) { console.log("Error listing directory", e) });
}, errorHandler);
}
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
dir.getFile("test.txt", { create: true, exclusive: false }, function (fileEntry) {
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = testFileMetadataRead;
fileWriter.onerror = function (e) { console.log("Error writing FILE", e) };
const blob = new Blob(["The quick brown fox jumps over the lazy dog!"], { type: 'text/plain' });
fileWriter.write(blob);
});
},
function (e) { console.log("Error creating new file", e) });
}, errorHandler);
```
## Result
```
Running cordova-browser@7.0.0 bundle.js:480:13
Successful file write... bundle.js:509:17
Contructor of FILE handle
function FileEntry(name, fullPath, fileSystem, nativeURL)
bundle.js:512:21
Getting FILE metadata
Object { isFile: true, isDirectory: false, name: "test.txt", fullPath: "/test.txt", filesystem: {…}, nativeURL: null }
Object { modificationTime: Date Sun Mar 22 2026 16:13:17 GMT+0000 (Greenwich Mean Time), size: 44 }
bundle.js:514:40
Contructor of DIRECTORY ENTRY handle
function FileEntry(name, fullPath, fileSystem, nativeURL)
bundle.js:522:29
Error getting DIR ENTRY metadata
Object { code: 1 }
bundle.js:525:48
```
### Environment, Platform, Device
Using Cordova Browser for testing on Linux Mint 22.3.
### Version information
cordova-browser@7.0.0
cordova-plugin-file@8.1.3
cordova-plugin-webpack@1.0.5
## Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng việc tái hiện deviceready sử dụng resolveLocalFileSystemURL, createReader().readEntries() và getMetadata(), đồng thời so sánh FileEntry được resolve trực tiếp với entry được directory trả về. Tái hiện bằng các phiên bản Cordova Browser và file-plugin được liệt kê; hoàn tất khi việc lấy metadata thành công cho cả hai handle mà không có NOT_FOUND_ERR.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- mobile-dev
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100