Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsenv/filesystem

Package Overview
Dependencies
Maintainers
2
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/filesystem - npm Package Compare versions

Comparing version 4.1.1 to 4.1.2

src/internal/track_resources.js

2

package.json
{
"name": "@jsenv/filesystem",
"version": "4.1.1",
"version": "4.1.2",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": {

@@ -33,3 +33,2 @@ import { Abort } from "@jsenv/abort"

const directoryChildNodeUrl = `${directoryUrl}${directoryItem}`
collectOperation.throwIfAborted()

@@ -36,0 +35,0 @@ const directoryChildNodeStats = await readEntryStat(

@@ -62,8 +62,8 @@ import { fileSystemPathToUrl } from "@jsenv/urls"

const extractDriveLetter = (ressource) => {
const extractDriveLetter = (resource) => {
// we still have the windows drive letter
if (/[a-zA-Z]/.test(ressource[1]) && ressource[2] === ":") {
return ressource[1]
if (/[a-zA-Z]/.test(resource[1]) && resource[2] === ":") {
return resource[1]
}
return null
}
import { readdir } from "node:fs"
import { urlToFileSystemPath } from "@jsenv/urls"
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"

@@ -7,9 +6,21 @@

const directoryUrl = assertAndNormalizeDirectoryUrl(url)
const directoryPath = urlToFileSystemPath(directoryUrl)
const directoryUrlObject = new URL(directoryUrl)
const startMs = Date.now()
let attemptCount = 0
const attempt = () => {
return readdirNaive(directoryPath, {
handleTooManyFilesOpenedError: async (error) => {
const attempt = async () => {
try {
const names = await new Promise((resolve, reject) => {
readdir(directoryUrlObject, (error, names) => {
if (error) {
reject(error)
} else {
resolve(names)
}
})
})
return names.map(encodeURIComponent)
} catch (e) {
// https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
if (e.code === "EMFILE" || e.code === "ENFILE") {
attemptCount++

@@ -19,12 +30,9 @@ const nowMs = Date.now()

if (timeSpentWaiting > emfileMaxWait) {
throw error
throw e
}
return new Promise((resolve) => {
setTimeout(() => {
resolve(attempt())
}, attemptCount)
})
},
})
await new Promise((resolve) => setTimeout(resolve), attemptCount)
return await attempt()
}
throw e
}
}

@@ -34,24 +42,1 @@

}
const readdirNaive = (
directoryPath,
{ handleTooManyFilesOpenedError = null } = {},
) => {
return new Promise((resolve, reject) => {
readdir(directoryPath, (error, names) => {
if (error) {
// https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
if (
handleTooManyFilesOpenedError &&
(error.code === "EMFILE" || error.code === "ENFILE")
) {
resolve(handleTooManyFilesOpenedError(error))
} else {
reject(error)
}
} else {
resolve(names)
}
})
})
}

@@ -9,3 +9,3 @@ import { readdirSync, statSync } from "node:fs"

import { createWatcher } from "./internal/createWatcher.js"
import { trackRessources } from "./internal/trackRessources.js"
import { trackResources } from "./internal/track_resources.js"

@@ -91,3 +91,3 @@ const isLinux = process.platform === "linux"

}
const tracker = trackRessources()
const tracker = trackResources()
const infoMap = new Map()

@@ -210,3 +210,3 @@ const readEntryInfo = (url) => {

// it existed and was replaced by something else
// we don't handle this as an update. We rather say the ressource
// we don't handle this as an update. We rather say the resource
// is lost and something else is found (call removed() then added())

@@ -213,0 +213,0 @@ handleEntryLost(previousInfo)

@@ -9,3 +9,3 @@ import { statSync } from "node:fs"

import { createWatcher } from "./internal/createWatcher.js"
import { trackRessources } from "./internal/trackRessources.js"
import { trackResources } from "./internal/track_resources.js"

@@ -49,3 +49,3 @@ export const registerFileLifecycle = (

const tracker = trackRessources()
const tracker = trackResources()

@@ -52,0 +52,0 @@ const handleFileFound = ({ existent }) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc