Skip to content

Commit 3e7edf4

Browse files
authored
Merge pull request joltup#124 from onlyling/master
fix: 🐛 fs.xxx normalizePath
2 parents 1512092 + 6b4ebb1 commit 3e7edf4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ReactNativeBlobUtilFS {
5454
static boolean writeFile(String path, String encoding, String data, final boolean append) {
5555
try {
5656
int written;
57+
path = ReactNativeBlobUtilUtils.normalizePath(path);
5758
File f = new File(path);
5859
File dir = f.getParentFile();
5960
if (!f.exists()) {
@@ -441,6 +442,7 @@ private static void deleteRecursive(File fileOrDirectory) throws IOException {
441442
* @param promise JS promise
442443
*/
443444
static void mkdir(String path, Promise promise) {
445+
path = ReactNativeBlobUtilUtils.normalizePath(path);
444446
File dest = new File(path);
445447
if (dest.exists()) {
446448
promise.reject("EEXIST", (dest.isDirectory() ? "Folder" : "File") + " '" + path + "' already exists");
@@ -468,6 +470,7 @@ static void mkdir(String path, Promise promise) {
468470
*/
469471
static void cp(String path, String dest, Callback callback) {
470472
path = ReactNativeBlobUtilUtils.normalizePath(path);
473+
dest = ReactNativeBlobUtilUtils.normalizePath(dest);
471474
InputStream in = null;
472475
OutputStream out = null;
473476
String message = "";
@@ -524,6 +527,8 @@ static void cp(String path, String dest, Callback callback) {
524527
* @param callback JS context callback
525528
*/
526529
static void mv(String path, String dest, Callback callback) {
530+
path = ReactNativeBlobUtilUtils.normalizePath(path);
531+
dest = ReactNativeBlobUtilUtils.normalizePath(dest);
527532
File src = new File(path);
528533
if (!src.exists()) {
529534
callback.invoke("Source file at path `" + path + "` does not exist");
@@ -627,6 +632,7 @@ static void ls(String path, Promise promise) {
627632
static void slice(String path, String dest, int start, int end, String encode, Promise promise) {
628633
try {
629634
path = ReactNativeBlobUtilUtils.normalizePath(path);
635+
dest = ReactNativeBlobUtilUtils.normalizePath(dest);
630636
File source = new File(path);
631637
if (source.isDirectory()) {
632638
promise.reject("EISDIR", "Expecting a file but '" + path + "' is a directory");
@@ -790,6 +796,8 @@ static void hash(String path, String algorithm, Promise promise) {
790796
promise.reject("EINVAL", "Invalid algorithm '" + algorithm + "', must be one of md5, sha1, sha224, sha256, sha384, sha512");
791797
return;
792798
}
799+
800+
path = ReactNativeBlobUtilUtils.normalizePath(path);
793801

794802
File file = new File(path);
795803

@@ -837,6 +845,7 @@ static void hash(String path, String algorithm, Promise promise) {
837845
*/
838846
static void createFile(String path, String data, String encoding, Promise promise) {
839847
try {
848+
path = ReactNativeBlobUtilUtils.normalizePath(path);
840849
File dest = new File(path);
841850
boolean created = dest.createNewFile();
842851
if (encoding.equals(ReactNativeBlobUtilConst.DATA_ENCODE_URI)) {
@@ -879,6 +888,7 @@ static void createFile(String path, String data, String encoding, Promise promis
879888
*/
880889
static void createFileASCII(String path, ReadableArray data, Promise promise) {
881890
try {
891+
path = ReactNativeBlobUtilUtils.normalizePath(path);
882892
File dest = new File(path);
883893
boolean created = dest.createNewFile();
884894
if (!created) {

0 commit comments

Comments
 (0)