Skip to content

Loading…

Fix ENAMETOOLONG errors on cache lock files, breaking package installation. #2592

Closed
wants to merge 1 commit into from

3 participants

@ghost

Old cache lock format:

{cache}/{sha(url)}-{url.replace(/[^a-zA-Z0-9]+/g, '-')}.lock

New cache lock format, which actually matches up with the comments
at the top of lib/cache.js:

{cache}/{sha(url)}.lock

In relatively frequent instances (see #2590), encoding the full path in the lock file name raises ENAMETOOLONG errors.

Reproducible by cloning npm and running npm install, on the following system, at least:

$ lsb_release -a

LSB Version:    core-2.0-ia32:core-2.0-noarch:core-3.0-ia32:core-3.0-noarch:core-3.1-ia32:core-3.1-noarch:core-3.2-ia32:core-3.2-noarch:core-4.0-ia32:core-4.0-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 12.04 LTS
Release:    12.04
Codename:   precise

Bug introduced in 09c3d08.

This patch successfully passes npm test.

Michael Smith Fix ENAMETOOLONG errors on cache lock files.
Old cache lock format:

    {cache}/{sha(url)}-{url.replace(/[^a-zA-Z0-9]+/g, '-')}.lock

New cache lock format, which actually matches up with the comments
in lib/cache.js:

    {cache}/{sha(url)}.lock
ce5896b
@isaacs
npm member

Hm. This does make the filenames a bit less useful, though.

Can we do something like, the first 8 chars of the sha, -, then just the first 16 chars of the url? It's really nice to be able to look at a lock file and know what generated it.

@trinitronx

I've verified that this fixes the problem (see my comment in #2598), but yes.. this does not keep lock files descriptive for developers ;-)

Upstream suggested fix is to use the statfs() syscall to check filename length limits (see bug description for #2598)

@krystiannowak

Done in 2598 - available with nodejs 0.8.2

@isaacs isaacs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2012
  1. Fix ENAMETOOLONG errors on cache lock files.

    Michael Smith committed
    Old cache lock format:
    
        {cache}/{sha(url)}-{url.replace(/[^a-zA-Z0-9]+/g, '-')}.lock
    
    New cache lock format, which actually matches up with the comments
    in lib/cache.js:
    
        {cache}/{sha(url)}.lock
Showing with 2 additions and 3 deletions.
  1. +2 −3 lib/cache.js
View
5 lib/cache.js
@@ -949,9 +949,8 @@ function deprCheck (data) {
}
function lockFileName (u) {
- var c = u.replace(/[^a-zA-Z0-9]+/g, '-')
- , h = crypto.createHash("sha1").update(u).digest("hex")
- return path.resolve(npm.config.get("cache"), h + "-" + c + ".lock")
+ var h = crypto.createHash("sha1").update(u).digest("hex")
+ return path.resolve(npm.config.get("cache"), h + ".lock")
}
var madeCache = false
Something went wrong with that request. Please try again.