@lvce-editor/file-system-process 5.5.0 → 5.6.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.
Files changed (2) hide show
  1. package/dist/index.js +17 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, constants } from 'node:fs';
2
2
  import * as fs from 'node:fs/promises';
3
3
  import * as os from 'node:os';
4
4
  import { fileURLToPath } from 'node:url';
@@ -1475,7 +1475,9 @@ const assertUri = uri => {
1475
1475
 
1476
1476
  const Utf8 = 'utf8';
1477
1477
 
1478
+ const EACCES = 'EACCES';
1478
1479
  const ENOENT = 'ENOENT';
1480
+ const EROFS = 'EROFS';
1479
1481
  const EXDEV = 'EXDEV';
1480
1482
 
1481
1483
  const getDisplayPath = path => {
@@ -1766,6 +1768,19 @@ const rename = async (oldUri, newUri) => {
1766
1768
  const getPathSeparator = () => {
1767
1769
  return '/';
1768
1770
  };
1771
+ const isReadonly = async uri => {
1772
+ assertUri(uri);
1773
+ const path = fileURLToPath(uri);
1774
+ try {
1775
+ await fs.access(path, constants.W_OK);
1776
+ return false;
1777
+ } catch (error) {
1778
+ if (error && (error.code === EACCES || error.code === EROFS)) {
1779
+ return true;
1780
+ }
1781
+ throw new VError(error, `Failed to check whether "${uri}" is readonly`);
1782
+ }
1783
+ };
1769
1784
  const stat = async uri => {
1770
1785
  const path = fileURLToPath(uri);
1771
1786
  const stats = await fs.stat(path);
@@ -1875,6 +1890,7 @@ const commandMap = {
1875
1890
  'FileSystem.exists': exists,
1876
1891
  'FileSystem.getFolderSize': getFolderSize,
1877
1892
  'FileSystem.getPathSeparator': getPathSeparator,
1893
+ 'FileSystem.isReadonly': isReadonly,
1878
1894
  'FileSystem.mkdir': mkdir,
1879
1895
  'FileSystem.readDirWithFileTypes': readDirWithFileTypes,
1880
1896
  'FileSystem.readFile': readFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-process",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "description": "File System Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",