@amazon-devices/expo-file-system 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -338,11 +338,49 @@ Promise ExponentFileSystem::copyAsync(NativeJSObject options) {
|
|
|
338
338
|
return;
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
+
// Run the copy on a background thread to avoid blocking the JS thread.
|
|
342
|
+
// std::filesystem::copy is synchronous and blocks for the whole copy
|
|
343
|
+
// duration, which trips the KeplerScript thread watchdog on large files.
|
|
341
344
|
try {
|
|
342
|
-
std::
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
345
|
+
std::thread([promise, from, to]() {
|
|
346
|
+
// If we cannot tell whether the destination already exists,
|
|
347
|
+
// assume it does. Then a failed copy never deletes data we did
|
|
348
|
+
// not create.
|
|
349
|
+
std::error_code existsError;
|
|
350
|
+
bool destExisted = true;
|
|
351
|
+
bool destExistsResult = std::filesystem::exists(to, existsError);
|
|
352
|
+
if (!existsError) {
|
|
353
|
+
destExisted = destExistsResult;
|
|
354
|
+
}
|
|
355
|
+
// A failed copy can leave a truncated destination, but only if
|
|
356
|
+
// this copy created it. Remove just that.
|
|
357
|
+
auto removePartialDestination = [&to, destExisted]() {
|
|
358
|
+
if (destExisted) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
std::error_code cleanupError;
|
|
362
|
+
std::filesystem::remove_all(to, cleanupError);
|
|
363
|
+
if (cleanupError) {
|
|
364
|
+
TMERROR(std::string("[ExponentFileSystem] could not remove partial destination, reason: ") + cleanupError.message());
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
try {
|
|
368
|
+
std::filesystem::copy(from, to, std::filesystem::copy_options::recursive);
|
|
369
|
+
promise->resolve(NULL);
|
|
370
|
+
} catch (std::exception& e) {
|
|
371
|
+
TMERROR(std::string("[ExponentFileSystem] file transfer exception, reason: ") + e.what());
|
|
372
|
+
removePartialDestination();
|
|
373
|
+
promise->reject(e.what());
|
|
374
|
+
} catch (...) {
|
|
375
|
+
TMERROR(std::string("[ExponentFileSystem] file transfer failed with an unknown exception"));
|
|
376
|
+
removePartialDestination();
|
|
377
|
+
promise->reject("unknown file transfer error");
|
|
378
|
+
}
|
|
379
|
+
}).detach();
|
|
380
|
+
} catch (std::exception& e) {
|
|
381
|
+
// The thread could not start. Reject here so the promise always
|
|
382
|
+
// settles and the JS caller does not wait forever.
|
|
383
|
+
TMERROR(std::string("[ExponentFileSystem] could not start copy thread, reason: ") + e.what());
|
|
346
384
|
promise->reject(e.what());
|
|
347
385
|
}
|
|
348
386
|
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@amazon-devices/expo-file-system", "version": "3.0.
|
|
1
|
+
{"name": "@amazon-devices/expo-file-system", "version": "3.0.2+15.8.0", "description": "Provides access to the local file system on the device.", "main": "build/index.js", "types": "build/index.d.ts", "sideEffects": false, "scripts": {"build": "expo-module build", "clean": "expo-module clean", "lint": "expo-module lint", "test": "expo-module test", "prepublishOnly": "expo-module prepublishOnly", "expo-module": "expo-module"}, "kepler": {"temporary-alias-for-package": {"name": "expo-file-system", "version": "15.8.0"}}, "keywords": ["react-native", "expo", "file-system", "file"], "repository": {"type": "git", "url": "https://github.com/expo/expo.git", "directory": "packages/expo-file-system"}, "bugs": {"url": "https://github.com/expo/expo/issues"}, "author": "650 Industries, Inc.", "license": "See license in LICENSE", "homepage": "https://docs.expo.dev/versions/latest/sdk/filesystem/", "dependencies": {"uuid": "^3.4.0", "@amazon-devices/keplerscript-turbomodule-api": "^1.0.0"}, "devDependencies": {"expo-module-scripts": "^3.0.0", "jest-expo": "~50.0.0-alpha.0", "@types/glob": "^7.2.0", "@types/minimatch": "^3.0.5"}, "peerDependencies": {"expo": "^50.0.0-alpha.1"}}
|