bare-fs 4.4.2 → 4.4.4

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.
package/binding.c CHANGED
@@ -20,6 +20,7 @@ typedef struct {
20
20
  js_ref_t *on_result;
21
21
 
22
22
  bool exiting;
23
+ bool inflight;
23
24
 
24
25
  js_deferred_teardown_t *teardown;
25
26
  } bare_fs_req_t;
@@ -79,9 +80,12 @@ bare_fs__on_request_teardown(js_deferred_teardown_t *handle, void *data) {
79
80
 
80
81
  req->exiting = true;
81
82
 
82
- err = uv_cancel((uv_req_t *) &req->handle);
83
+ if (req->inflight) {
84
+ err = uv_cancel((uv_req_t *) &req->handle);
85
+ if (err < 0) return;
86
+ }
83
87
 
84
- if (err != 0) bare_fs__request_destroy(req);
88
+ bare_fs__request_destroy(req);
85
89
  }
86
90
 
87
91
  static inline void
@@ -90,6 +94,8 @@ bare_fs__on_request_result(uv_fs_t *handle) {
90
94
 
91
95
  bare_fs_req_t *req = (bare_fs_req_t *) handle;
92
96
 
97
+ req->inflight = false;
98
+
93
99
  if (req->exiting) return bare_fs__request_destroy(req);
94
100
 
95
101
  js_env_t *env = req->env;
@@ -135,6 +141,30 @@ bare_fs__on_request_result(uv_fs_t *handle) {
135
141
  assert(err == 0);
136
142
  }
137
143
 
144
+ static inline int
145
+ bare_fs__request_pending(js_env_t *env, bare_fs_req_t *req, bool async, int *result) {
146
+ int err;
147
+
148
+ if (async) {
149
+ req->inflight = true;
150
+
151
+ return 0;
152
+ }
153
+
154
+ int status = req->handle.result;
155
+
156
+ if (status < 0) {
157
+ err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
158
+ assert(err == 0);
159
+
160
+ return -1;
161
+ }
162
+
163
+ if (result) *result = status;
164
+
165
+ return 1;
166
+ }
167
+
138
168
  static js_value_t *
139
169
  bare_fs_request_init(js_env_t *env, js_callback_info_t *info) {
140
170
  int err;
@@ -155,6 +185,7 @@ bare_fs_request_init(js_env_t *env, js_callback_info_t *info) {
155
185
 
156
186
  req->env = env;
157
187
  req->exiting = false;
188
+ req->inflight = false;
158
189
 
159
190
  err = js_create_reference(env, argv[0], 1, &req->ctx);
160
191
  assert(err == 0);
@@ -427,16 +458,9 @@ bare_fs__open(js_env_t *env, js_callback_info_t *info, bool async) {
427
458
  err = uv_fs_open(loop, &req->handle, (char *) path, flags, mode, async ? bare_fs__on_open : NULL);
428
459
  (void) err;
429
460
 
430
- if (async) return NULL;
431
-
432
- int status = req->handle.result;
433
-
434
- if (status < 0) {
435
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
436
- assert(err == 0);
437
-
438
- return NULL;
439
- }
461
+ int status;
462
+ err = bare_fs__request_pending(env, req, async, &status);
463
+ if (err != 1) return NULL;
440
464
 
441
465
  js_value_t *result;
442
466
  err = js_create_int32(env, status, &result);
@@ -487,14 +511,8 @@ bare_fs__close(js_env_t *env, js_callback_info_t *info, bool async) {
487
511
  err = uv_fs_close(loop, &req->handle, fd, async ? bare_fs__on_close : NULL);
488
512
  (void) err;
489
513
 
490
- if (async) return NULL;
491
-
492
- int status = req->handle.result;
493
-
494
- if (status < 0) {
495
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
496
- assert(err == 0);
497
- }
514
+ err = bare_fs__request_pending(env, req, async, NULL);
515
+ (void) err;
498
516
 
499
517
  return NULL;
500
518
  }
@@ -545,14 +563,8 @@ bare_fs__access(js_env_t *env, js_callback_info_t *info, bool async) {
545
563
  err = uv_fs_access(loop, &req->handle, (char *) path, mode, async ? bare_fs__on_access : NULL);
546
564
  (void) err;
547
565
 
548
- if (async) return NULL;
549
-
550
- int status = req->handle.result;
551
-
552
- if (status < 0) {
553
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
554
- assert(err == 0);
555
- }
566
+ err = bare_fs__request_pending(env, req, async, NULL);
567
+ (void) err;
556
568
 
557
569
  return NULL;
558
570
  }
@@ -621,16 +633,9 @@ bare_fs__read(js_env_t *env, js_callback_info_t *info, bool async) {
621
633
  err = uv_fs_read(loop, &req->handle, fd, &buf, 1, pos, async ? bare_fs__on_read : NULL);
622
634
  (void) err;
623
635
 
624
- if (async) return NULL;
625
-
626
- int status = req->handle.result;
627
-
628
- if (status < 0) {
629
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
630
- assert(err == 0);
631
-
632
- return NULL;
633
- }
636
+ int status;
637
+ err = bare_fs__request_pending(env, req, async, &status);
638
+ if (err != 1) return NULL;
634
639
 
635
640
  js_value_t *result;
636
641
  err = js_create_int32(env, status, &result);
@@ -708,16 +713,9 @@ bare_fs__readv(js_env_t *env, js_callback_info_t *info, bool async) {
708
713
  free(elements);
709
714
  free(bufs);
710
715
 
711
- if (async) return NULL;
712
-
713
- int status = req->handle.result;
714
-
715
- if (status < 0) {
716
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
717
- assert(err == 0);
718
-
719
- return NULL;
720
- }
716
+ int status;
717
+ err = bare_fs__request_pending(env, req, async, &status);
718
+ if (err != 1) return NULL;
721
719
 
722
720
  js_value_t *result;
723
721
  err = js_create_int32(env, status, &result);
@@ -790,16 +788,9 @@ bare_fs__write(js_env_t *env, js_callback_info_t *info, bool async) {
790
788
  err = uv_fs_write(loop, &req->handle, fd, &buf, 1, pos, async ? bare_fs__on_write : NULL);
791
789
  (void) err;
792
790
 
793
- if (async) return NULL;
794
-
795
- int status = req->handle.result;
796
-
797
- if (status < 0) {
798
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
799
- assert(err == 0);
800
-
801
- return NULL;
802
- }
791
+ int status;
792
+ err = bare_fs__request_pending(env, req, async, &status);
793
+ if (err != 1) return NULL;
803
794
 
804
795
  js_value_t *result;
805
796
  err = js_create_int32(env, status, &result);
@@ -878,16 +869,9 @@ bare_fs__writev(js_env_t *env, js_callback_info_t *info, bool async) {
878
869
  free(elements);
879
870
  free(bufs);
880
871
 
881
- if (async) return NULL;
882
-
883
- int status = req->handle.result;
884
-
885
- if (status < 0) {
886
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
887
- assert(err == 0);
888
-
889
- return NULL;
890
- }
872
+ int status;
873
+ err = bare_fs__request_pending(env, req, async, &status);
874
+ if (err != 1) return NULL;
891
875
 
892
876
  js_value_t *result;
893
877
  err = js_create_int32(env, status, &result);
@@ -942,14 +926,8 @@ bare_fs__ftruncate(js_env_t *env, js_callback_info_t *info, bool async) {
942
926
  err = uv_fs_ftruncate(loop, &req->handle, fd, len, async ? bare_fs__on_ftruncate : NULL);
943
927
  (void) err;
944
928
 
945
- if (async) return NULL;
946
-
947
- int status = req->handle.result;
948
-
949
- if (status < 0) {
950
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
951
- assert(err == 0);
952
- }
929
+ err = bare_fs__request_pending(env, req, async, NULL);
930
+ (void) err;
953
931
 
954
932
  return NULL;
955
933
  }
@@ -1000,14 +978,8 @@ bare_fs__chmod(js_env_t *env, js_callback_info_t *info, bool async) {
1000
978
  err = uv_fs_chmod(loop, &req->handle, (char *) path, mode, async ? bare_fs__on_chmod : NULL);
1001
979
  (void) err;
1002
980
 
1003
- if (async) return NULL;
1004
-
1005
- int status = req->handle.result;
1006
-
1007
- if (status < 0) {
1008
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1009
- assert(err == 0);
1010
- }
981
+ err = bare_fs__request_pending(env, req, async, NULL);
982
+ (void) err;
1011
983
 
1012
984
  return NULL;
1013
985
  }
@@ -1058,14 +1030,8 @@ bare_fs__fchmod(js_env_t *env, js_callback_info_t *info, bool async) {
1058
1030
  err = uv_fs_fchmod(loop, &req->handle, fd, mode, async ? bare_fs__on_fchmod : NULL);
1059
1031
  (void) err;
1060
1032
 
1061
- if (async) return NULL;
1062
-
1063
- int status = req->handle.result;
1064
-
1065
- if (status < 0) {
1066
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1067
- assert(err == 0);
1068
- }
1033
+ err = bare_fs__request_pending(env, req, async, NULL);
1034
+ (void) err;
1069
1035
 
1070
1036
  return NULL;
1071
1037
  }
@@ -1120,14 +1086,8 @@ bare_fs__utimes(js_env_t *env, js_callback_info_t *info, bool async) {
1120
1086
  err = uv_fs_utime(loop, &req->handle, (char *) path, atime, mtime, async ? bare_fs__on_utimes : NULL);
1121
1087
  (void) err;
1122
1088
 
1123
- if (async) return NULL;
1124
-
1125
- int status = req->handle.result;
1126
-
1127
- if (status < 0) {
1128
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1129
- assert(err == 0);
1130
- }
1089
+ err = bare_fs__request_pending(env, req, async, NULL);
1090
+ (void) err;
1131
1091
 
1132
1092
  return NULL;
1133
1093
  }
@@ -1178,14 +1138,8 @@ bare_fs__rename(js_env_t *env, js_callback_info_t *info, bool async) {
1178
1138
  err = uv_fs_rename(loop, &req->handle, (char *) src, (char *) dst, async ? bare_fs__on_rename : NULL);
1179
1139
  (void) err;
1180
1140
 
1181
- if (async) return NULL;
1182
-
1183
- int status = req->handle.result;
1184
-
1185
- if (status < 0) {
1186
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1187
- assert(err == 0);
1188
- }
1141
+ err = bare_fs__request_pending(env, req, async, NULL);
1142
+ (void) err;
1189
1143
 
1190
1144
  return NULL;
1191
1145
  }
@@ -1240,14 +1194,8 @@ bare_fs__copyfile(js_env_t *env, js_callback_info_t *info, bool async) {
1240
1194
  err = uv_fs_copyfile(loop, &req->handle, (char *) src, (char *) dst, mode, async ? bare_fs__on_copyfile : NULL);
1241
1195
  (void) err;
1242
1196
 
1243
- if (async) return NULL;
1244
-
1245
- int status = req->handle.result;
1246
-
1247
- if (status < 0) {
1248
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1249
- assert(err == 0);
1250
- }
1197
+ err = bare_fs__request_pending(env, req, async, NULL);
1198
+ (void) err;
1251
1199
 
1252
1200
  return NULL;
1253
1201
  }
@@ -1298,14 +1246,8 @@ bare_fs__mkdir(js_env_t *env, js_callback_info_t *info, bool async) {
1298
1246
  err = uv_fs_mkdir(loop, &req->handle, (char *) path, mode, async ? bare_fs__on_mkdir : NULL);
1299
1247
  (void) err;
1300
1248
 
1301
- if (async) return NULL;
1302
-
1303
- int status = req->handle.result;
1304
-
1305
- if (status < 0) {
1306
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1307
- assert(err == 0);
1308
- }
1249
+ err = bare_fs__request_pending(env, req, async, NULL);
1250
+ (void) err;
1309
1251
 
1310
1252
  return NULL;
1311
1253
  }
@@ -1352,14 +1294,8 @@ bare_fs__rmdir(js_env_t *env, js_callback_info_t *info, bool async) {
1352
1294
  err = uv_fs_rmdir(loop, &req->handle, (char *) path, async ? bare_fs__on_rmdir : NULL);
1353
1295
  (void) err;
1354
1296
 
1355
- if (async) return NULL;
1356
-
1357
- int status = req->handle.result;
1358
-
1359
- if (status < 0) {
1360
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1361
- assert(err == 0);
1362
- }
1297
+ err = bare_fs__request_pending(env, req, async, NULL);
1298
+ (void) err;
1363
1299
 
1364
1300
  return NULL;
1365
1301
  }
@@ -1406,14 +1342,8 @@ bare_fs__stat(js_env_t *env, js_callback_info_t *info, bool async) {
1406
1342
  err = uv_fs_stat(loop, &req->handle, (char *) path, async ? bare_fs__on_stat : NULL);
1407
1343
  (void) err;
1408
1344
 
1409
- if (async) return NULL;
1410
-
1411
- int status = req->handle.result;
1412
-
1413
- if (status < 0) {
1414
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1415
- assert(err == 0);
1416
- }
1345
+ err = bare_fs__request_pending(env, req, async, NULL);
1346
+ (void) err;
1417
1347
 
1418
1348
  return NULL;
1419
1349
  }
@@ -1460,14 +1390,8 @@ bare_fs__lstat(js_env_t *env, js_callback_info_t *info, bool async) {
1460
1390
  err = uv_fs_lstat(loop, &req->handle, (char *) path, async ? bare_fs__on_lstat : NULL);
1461
1391
  (void) err;
1462
1392
 
1463
- if (async) return NULL;
1464
-
1465
- int status = req->handle.result;
1466
-
1467
- if (status < 0) {
1468
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1469
- assert(err == 0);
1470
- }
1393
+ err = bare_fs__request_pending(env, req, async, NULL);
1394
+ (void) err;
1471
1395
 
1472
1396
  return NULL;
1473
1397
  }
@@ -1514,14 +1438,8 @@ bare_fs__fstat(js_env_t *env, js_callback_info_t *info, bool async) {
1514
1438
  err = uv_fs_fstat(loop, &req->handle, fd, async ? bare_fs__on_fstat : NULL);
1515
1439
  (void) err;
1516
1440
 
1517
- if (async) return NULL;
1518
-
1519
- int status = req->handle.result;
1520
-
1521
- if (status < 0) {
1522
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1523
- assert(err == 0);
1524
- }
1441
+ err = bare_fs__request_pending(env, req, async, NULL);
1442
+ (void) err;
1525
1443
 
1526
1444
  return NULL;
1527
1445
  }
@@ -1568,14 +1486,8 @@ bare_fs__unlink(js_env_t *env, js_callback_info_t *info, bool async) {
1568
1486
  err = uv_fs_unlink(loop, &req->handle, (char *) path, async ? bare_fs__on_unlink : NULL);
1569
1487
  (void) err;
1570
1488
 
1571
- if (async) return NULL;
1572
-
1573
- int status = req->handle.result;
1574
-
1575
- if (status < 0) {
1576
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1577
- assert(err == 0);
1578
- }
1489
+ err = bare_fs__request_pending(env, req, async, NULL);
1490
+ (void) err;
1579
1491
 
1580
1492
  return NULL;
1581
1493
  }
@@ -1622,14 +1534,8 @@ bare_fs__realpath(js_env_t *env, js_callback_info_t *info, bool async) {
1622
1534
  err = uv_fs_realpath(loop, &req->handle, (char *) path, async ? bare_fs__on_realpath : NULL);
1623
1535
  (void) err;
1624
1536
 
1625
- if (async) return NULL;
1626
-
1627
- int status = req->handle.result;
1628
-
1629
- if (status < 0) {
1630
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1631
- assert(err == 0);
1632
- }
1537
+ err = bare_fs__request_pending(env, req, async, NULL);
1538
+ (void) err;
1633
1539
 
1634
1540
  return NULL;
1635
1541
  }
@@ -1676,14 +1582,8 @@ bare_fs__readlink(js_env_t *env, js_callback_info_t *info, bool async) {
1676
1582
  err = uv_fs_readlink(loop, &req->handle, (char *) path, async ? bare_fs__on_readlink : NULL);
1677
1583
  (void) err;
1678
1584
 
1679
- if (async) return NULL;
1680
-
1681
- int status = req->handle.result;
1682
-
1683
- if (status < 0) {
1684
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1685
- assert(err == 0);
1686
- }
1585
+ err = bare_fs__request_pending(env, req, async, NULL);
1586
+ (void) err;
1687
1587
 
1688
1588
  return NULL;
1689
1589
  }
@@ -1738,14 +1638,8 @@ bare_fs__symlink(js_env_t *env, js_callback_info_t *info, bool async) {
1738
1638
  err = uv_fs_symlink(loop, &req->handle, (char *) target, (char *) path, flags, async ? bare_fs__on_symlink : NULL);
1739
1639
  (void) err;
1740
1640
 
1741
- if (async) return NULL;
1742
-
1743
- int status = req->handle.result;
1744
-
1745
- if (status < 0) {
1746
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1747
- assert(err == 0);
1748
- }
1641
+ err = bare_fs__request_pending(env, req, async, NULL);
1642
+ (void) err;
1749
1643
 
1750
1644
  return NULL;
1751
1645
  }
@@ -1792,14 +1686,8 @@ bare_fs__opendir(js_env_t *env, js_callback_info_t *info, bool async) {
1792
1686
  err = uv_fs_opendir(loop, &req->handle, (char *) path, async ? bare_fs__on_opendir : NULL);
1793
1687
  (void) err;
1794
1688
 
1795
- if (async) return NULL;
1796
-
1797
- int status = req->handle.result;
1798
-
1799
- if (status < 0) {
1800
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1801
- assert(err == 0);
1802
- }
1689
+ err = bare_fs__request_pending(env, req, async, NULL);
1690
+ (void) err;
1803
1691
 
1804
1692
  return NULL;
1805
1693
  }
@@ -1859,16 +1747,8 @@ bare_fs__readdir(js_env_t *env, js_callback_info_t *info, bool async) {
1859
1747
  err = uv_fs_readdir(loop, &req->handle, dir->handle, async ? bare_fs__on_readdir : NULL);
1860
1748
  (void) err;
1861
1749
 
1862
- if (async) return result;
1863
-
1864
- int status = req->handle.result;
1865
-
1866
- if (status < 0) {
1867
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1868
- assert(err == 0);
1869
-
1870
- return NULL;
1871
- }
1750
+ err = bare_fs__request_pending(env, req, async, NULL);
1751
+ (void) err;
1872
1752
 
1873
1753
  return result;
1874
1754
  }
@@ -1915,14 +1795,8 @@ bare_fs__closedir(js_env_t *env, js_callback_info_t *info, bool async) {
1915
1795
  err = uv_fs_closedir(loop, &req->handle, dir->handle, async ? bare_fs__on_closedir : NULL);
1916
1796
  (void) err;
1917
1797
 
1918
- if (async) return NULL;
1919
-
1920
- int status = req->handle.result;
1921
-
1922
- if (status < 0) {
1923
- err = js_throw_error(env, uv_err_name(status), uv_strerror(status));
1924
- assert(err == 0);
1925
- }
1798
+ err = bare_fs__request_pending(env, req, async, NULL);
1799
+ (void) err;
1926
1800
 
1927
1801
  return NULL;
1928
1802
  }
package/index.js CHANGED
@@ -20,11 +20,8 @@ class FileRequest {
20
20
  }
21
21
 
22
22
  static return(req) {
23
- // TODO
24
- // if (this._free.length < 32) this._free.push(req.reset())
25
- // else req.destroy()
26
-
27
- req.destroy()
23
+ if (this._free.length < 32) this._free.push(req.reset())
24
+ else req.destroy()
28
25
  }
29
26
 
30
27
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.4.2",
3
+ "version": "4.4.4",
4
4
  "description": "Native file system operations for Javascript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -54,6 +54,7 @@
54
54
  },
55
55
  "devDependencies": {
56
56
  "bare-buffer": "^3.0.2",
57
+ "bare-crypto": "^1.11.2",
57
58
  "brittle": "^3.1.1",
58
59
  "cmake-bare": "^1.1.7",
59
60
  "prettier": "^3.4.1",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file