@gjsify/fs 0.38.1 → 0.39.0
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/lib/esm/fd-io.js +1 -1
- package/package.json +8 -8
package/lib/esm/fd-io.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{createNodeError as e}from"./errors.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import r from"@girs/giounix-2.0";const
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{createNodeError as e}from"./errors.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import r from"@girs/giounix-2.0";import{splitPathComponents as i}from"@gjsify/utils/core";const a={EPERM:-1,ENOENT:-2,EIO:-5,ENXIO:-6,EBADF:-9,EACCES:-13,EEXIST:-17,ENOTDIR:-20,EISDIR:-21,EINVAL:-22,ENFILE:-23,EMFILE:-24,ETXTBSY:-26,ENOSPC:-28,ESPIPE:-29,EROFS:-30,ENAMETOOLONG:-36,ENOTEMPTY:-39,ELOOP:-40};function fsError(e,t,n,r){let i=`${e}: ${describe(e)}, ${t}`;n&&(i+=` '${n}'`),r&&(i+=` -> '${r}'`);let o=Error(i);return o.code=e,o.errno=a[e]??-1,o.syscall=t,n&&(o.path=n),r&&(o.dest=r),o}function describe(e){switch(e){case`ENOENT`:return`no such file or directory`;case`EEXIST`:return`file already exists`;case`EACCES`:return`permission denied`;case`EISDIR`:return`illegal operation on a directory`;case`ENOTDIR`:return`not a directory`;case`EBADF`:return`bad file descriptor`;case`EPERM`:return`operation not permitted`;case`EINVAL`:return`invalid argument`;case`ELOOP`:return`too many symbolic links encountered`;case`ENAMETOOLONG`:return`name too long`;case`EMFILE`:return`too many open files`;case`ENFILE`:return`file table overflow`;case`EROFS`:return`read-only file system`;case`ESPIPE`:return`invalid seek`;case`ENXIO`:return`no such device or address`;default:return`i/o error`}}let o=null;function hasProcFd(){return o===null&&(o=t.file_test(`/proc/self/fd`,t.FileTest.IS_DIR)),o}function fdPath(e){return hasProcFd()?`/proc/self/fd/${e}`:null}function openFd(e,n,r){let i=t.open(e,n.posix,r);if(i<0)throw classifyOpenFailure(e,n);return i}function closeFd(e){t.close(e)}function classifyOpenFailure(e,t){let r=nameTooLong(e,`open`);if(r)return r;let i=n.File.new_for_path(e),a=null,o=!1;try{let e=i.query_info(`standard::type,standard::symlink-target,unix::mode,access::can-read,access::can-write`,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);answered(e)?a=e:o=!0}catch{a=null}if(o)return refusalNotAboutThePath(e,t,i,null);if(a){if(t.excl)return fsError(`EEXIST`,`open`,e);if(a.get_file_type()===n.FileType.SYMBOLIC_LINK&&!t.nofollow){let n=walkSymlinkChain(i);if(n===`loop`)return fsError(`ELOOP`,`open`,e);if(n===`too-long`)return fsError(`ENAMETOOLONG`,`open`,e);if(n===`dangling`&&!t.creat)return fsError(`ENOENT`,`open`,e)}return a.get_file_type()===n.FileType.DIRECTORY&&t.writable?fsError(`EISDIR`,`open`,e):t.directory&&a.get_file_type()!==n.FileType.DIRECTORY?fsError(`ENOTDIR`,`open`,e):refusalNotAboutThePath(e,t,i,a)}if(ancestorIsNotADirectory(i))return fsError(`ENOTDIR`,`open`,e);if(!t.creat)return fsError(`ENOENT`,`open`,e);let s=i.get_parent();if(!s)return fsError(`ENOENT`,`open`,e);try{s.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null)}catch{return fsError(`ENOENT`,`open`,e)}return refusalNotAboutThePath(e,t,i,null)}function ancestorIsNotADirectory(e){for(let t=e.get_parent();t;t=t.get_parent()){let e;try{e=t.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null)}catch{continue}return answered(e)?e.get_file_type()!==n.FileType.DIRECTORY:!1}return!1}function answered(e){return e!==null&&e.has_attribute(`standard::type`)}function nameTooLong(e,t){let n=new TextEncoder;if(n.encode(e).length>4096)return fsError(`ENAMETOOLONG`,t,e);for(let r of i(e))if(n.encode(r).length>255)return fsError(`ENAMETOOLONG`,t,e);return null}function walkSymlinkChain(e){let t=new TextEncoder,r=e;for(let e=0;e<40;e++){let e;try{e=r.query_info(`standard::type,standard::symlink-target`,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch{return`dangling`}if(!answered(e)||e.get_file_type()!==n.FileType.SYMBOLIC_LINK)return`resolved`;let i=e.get_symlink_target();if(!i)return`dangling`;if(t.encode(i).length>4096)return`too-long`;let a=r.get_parent();r=i.startsWith(`/`)?n.File.new_for_path(i):a?.resolve_relative_path(i)??n.File.new_for_path(i)}return`loop`}function refusalNotAboutThePath(e,n,r,i){let a=t.open(`/dev/null`,0,0);if(a<0)return fsError(`EMFILE`,`open`,e);t.close(a);let o=i!==null&&(i.get_attribute_uint32(`unix::mode`)&146)==0;if((n.writable||n.creat)&&!o)try{if(r.query_filesystem_info(`filesystem::readonly`,null).get_attribute_boolean(`filesystem::readonly`))return fsError(`EROFS`,`open`,e)}catch{}return i&¬hingOnTheOtherEnd(n,i)?fsError(`ENXIO`,`open`,e):fsError(`EACCES`,`open`,e)}function nothingOnTheOtherEnd(e,t){if(!t.has_attribute(`unix::mode`))return!1;let n=t.get_attribute_uint32(`unix::mode`)&61440;if(!(n===8192||n===24576||n===4096))return!1;let permits=e=>t.has_attribute(e)&&t.get_attribute_boolean(e);return!(e.readable&&!permits(`access::can-read`)||e.writable&&!permits(`access::can-write`))}function classifyMkdirFailure(e){let t=nameTooLong(e,`mkdir`);if(t)return t;let r=n.File.new_for_path(e);try{return answered(r.query_info(`standard::type`,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null))?fsError(`EEXIST`,`mkdir`,e):fsError(`EACCES`,`mkdir`,e)}catch{}let i=r.get_parent();if(!i)return fsError(`ENOENT`,`mkdir`,e);try{let t=i.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null);if(answered(t)&&t.get_file_type()!==n.FileType.DIRECTORY)return fsError(`ENOTDIR`,`mkdir`,e)}catch{return fsError(`ENOENT`,`mkdir`,e)}return fsError(`EACCES`,`mkdir`,e)}const s=new Map,c=new Map,l=new Map;function seekHandle(e){let n=s.get(e);return n||(n=t.IOChannel.unix_new(e),n.set_encoding(null),n.set_buffered(!1),n.set_close_on_unref(!1),s.set(e,n)),n}function input(e){let t=c.get(e);return t||(t=r.InputStream.new(e,!1),c.set(e,t)),t}function output(e){let t=l.get(e);return t||(t=r.OutputStream.new(e,!1),l.set(e,t)),t}const u=new Map;function isSeekableFd(e,t){let n=u.get(e);return n===void 0&&(n=probeSeekable(e,t),u.set(e,n)),n}function probeSeekable(e,r){try{let t=n.File.new_for_path(fdPath(e)??r).query_info(`unix::mode`,n.FileQueryInfoFlags.NONE,null);if(t.has_attribute(`unix::mode`)){let e=t.get_attribute_uint32(`unix::mode`)&61440;if(e===4096||e===49152)return!1}}catch{}try{return seekHandle(e).seek_position(0,t.SeekType.CUR),!0}catch{return!1}}function seekFd(e,n){seekHandle(e).seek_position(n,t.SeekType.SET)}function tellFd(e){if(!hasProcFd())return null;try{let[n,r]=t.file_get_contents(`/proc/self/fdinfo/${e}`);if(!n)return null;let i=/^pos:\s*(\d+)/m.exec(new TextDecoder().decode(r));return i?Number(i[1]):null}catch{return null}}function readFd(e,t){return t<=0?new Uint8Array:input(e).read_bytes(t,null).get_data()??new Uint8Array}function writeFd(e,t){if(t.length===0)return 0;let[,n]=output(e).write_all(t,null);return n}function fsyncFd(e){output(e).flush(null),t.fsync(e)}function releaseFd(e){let t=l.get(e);if(t)try{t.flush(null)}catch{}s.delete(e),c.delete(e),l.delete(e),u.delete(e)}function sizeOfFd(e,t){let r=fdPath(e)??t,i=n.File.new_for_path(r).query_info(`standard::size`,n.FileQueryInfoFlags.NONE,null);return Number(i.get_size())}function truncateFd(t,r,i){let a=n.File.new_for_path(fdPath(t)??i),o;try{let e=a.append_to(n.FileCreateFlags.NONE,null);try{e.truncate(r,null)}finally{e.close(null)}return}catch(e){o=e}try{let e=a.open_readwrite(null);try{e.get_output_stream().truncate(r,null)}finally{e.close(null)}return}catch{}throw e(o,`ftruncate`,i)}export{answered,classifyMkdirFailure,classifyOpenFailure,closeFd,fdPath,fsError,fsyncFd,hasProcFd,isSeekableFd,openFd,readFd,releaseFd,seekFd,sizeOfFd,tellFd,truncateFd,writeFd};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/fs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Node.js fs module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"fs"
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@gjsify/cli": "^0.
|
|
70
|
-
"@gjsify/unit": "^0.
|
|
69
|
+
"@gjsify/cli": "^0.39.0",
|
|
70
|
+
"@gjsify/unit": "^0.39.0",
|
|
71
71
|
"@types/node": "^25.9.2",
|
|
72
72
|
"typescript": "^6.0.3"
|
|
73
73
|
},
|
|
@@ -75,11 +75,11 @@
|
|
|
75
75
|
"@girs/gio-2.0": "^4.1.0",
|
|
76
76
|
"@girs/giounix-2.0": "^4.1.0",
|
|
77
77
|
"@girs/glib-2.0": "^4.1.0",
|
|
78
|
-
"@gjsify/buffer": "^0.
|
|
79
|
-
"@gjsify/events": "^0.
|
|
80
|
-
"@gjsify/stream": "^0.
|
|
81
|
-
"@gjsify/url": "^0.
|
|
82
|
-
"@gjsify/utils": "^0.
|
|
78
|
+
"@gjsify/buffer": "^0.39.0",
|
|
79
|
+
"@gjsify/events": "^0.39.0",
|
|
80
|
+
"@gjsify/stream": "^0.39.0",
|
|
81
|
+
"@gjsify/url": "^0.39.0",
|
|
82
|
+
"@gjsify/utils": "^0.39.0"
|
|
83
83
|
},
|
|
84
84
|
"gjsify": {
|
|
85
85
|
"runtimes": {
|