Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Try using UNC paths to work around windows weirdness
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Nov 18, 2011
1 parent bcec334 commit 3e5d171
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 67 deletions.
3 changes: 3 additions & 0 deletions lib/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ function decorate (er, code, me) {
er.path = er.path || me.path
er.fstream_type = me.type
er.fstream_path = me.path
if (me._path !== me.path) {
er.fstream_unc_path = me._path
}
er.fstream_class = me.constructor.name
er.fstream_stack = new Error().stack.split(/\n/).slice(3).map(function (s) {
return s.replace(/^ at /, "")
Expand Down
12 changes: 6 additions & 6 deletions lib/dir-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function DirReader (props) {

DirReader.prototype._getEntries = function () {
var me = this
fs.readdir(me.path, function (er, entries) {
fs.readdir(me._path, function (er, entries) {
if (er) return me.error(er)
me._entries = entries
me._length = entries.length
Expand All @@ -58,7 +58,7 @@ DirReader.prototype._read = function () {

me._index ++
if (me._index >= me._length) {
// console.error(" DR End/close", me.path)
// console.error(" DR End/close", me._path)
me.emit("end")
me.emit("close")
return
Expand All @@ -67,7 +67,7 @@ DirReader.prototype._read = function () {
// ok, handle this one, then.

// save creating a proxy, by stat'ing the thing now.
var p = path.resolve(me.path, me._entries[me._index])
var p = path.resolve(me._path, me._entries[me._index])
// set this to prevent trying to _read() again in the stat time.
me._currentEntry = p
fs[ me.props.follow ? "stat" : "lstat" ](p, function (er, stat) {
Expand Down Expand Up @@ -102,7 +102,7 @@ DirReader.prototype._read = function () {
})

entry.on("ready", function EMITCHILD () {
// console.error("DR emit child", entry.path)
// console.error("DR emit child", entry._path)
if (me._paused) {
// console.error(" DR emit child - try again later")
// pause the child, and emit the "entry" event once we drain.
Expand Down Expand Up @@ -154,10 +154,10 @@ DirReader.prototype.resume = function (who) {
who = who || me

me._paused = false
// console.error("DR Emit Resume", me.path)
// console.error("DR Emit Resume", me._path)
me.emit("resume", who)
if (me._paused) {
// console.error("DR Re-paused", me.path)
// console.error("DR Re-paused", me._path)
return
}

Expand Down
20 changes: 10 additions & 10 deletions lib/dir-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function DirWriter (props) {

DirWriter.prototype._create = function () {
var me = this
mkdir(me.path, Writer.dirmode, function (er) {
mkdir(me._path, Writer.dirmode, function (er) {
if (er) return me.error(er)
// ready to start getting entries!
me.ready = true
Expand All @@ -56,7 +56,7 @@ DirWriter.prototype.end = function () {
DirWriter.prototype.add = function (entry) {
var me = this

// console.error("\tadd", entry.path, "->", me.path)
// console.error("\tadd", entry._path, "->", me._path)
collect(entry)
if (!me.ready || me._currentEntry) {
me._buffer.push(entry)
Expand Down Expand Up @@ -90,7 +90,7 @@ DirWriter.prototype._process = function () {
}

me._processing = true
// console.error("DW Entry", entry.path)
// console.error("DW Entry", entry._path)

me.emit("entry", entry)

Expand All @@ -99,8 +99,8 @@ DirWriter.prototype._process = function () {
// don't allow recursive copying
var p = entry
do {
if (p.path === me.root.path || p.path === me.path) {
// console.error("DW Exit (recursive)", entry.basename, me.path)
if (p._path === me.root._path || p._path === me._path) {
// console.error("DW Exit (recursive)", entry.basename, me._path)
me._processing = false
if (entry._collected) entry.pipe()
return me._process()
Expand All @@ -115,12 +115,12 @@ DirWriter.prototype._process = function () {
, type: entry.type
, depth: me.depth + 1 }

var p = entry.path || entry.props.path
var p = entry._path || entry.props._path
if (entry.parent) {
p = p.substr(entry.parent.path.length + 1)
p = p.substr(entry.parent._path.length + 1)
}
// get rid of any ../../ shenanigans
props.path = path.join(me.path, path.join("/", p))
props._path = path.join(me._path, path.join("/", p))

// all the rest of the stuff, copy over from the source.
Object.keys(entry.props).forEach(function (k) {
Expand All @@ -132,8 +132,8 @@ DirWriter.prototype._process = function () {
// not sure at this point what kind of writer this is.
var child = me._currentChild = new Writer(props)
child.on("ready", function () {
// console.error("DW Child Ready", child.type, child.path)
// console.error(" resuming", entry.path)
// console.error("DW Child Ready", child.type, child._path)
// console.error(" resuming", entry._path)
entry.pipe(child)
entry.resume()
})
Expand Down
32 changes: 15 additions & 17 deletions lib/file-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var fs = require("graceful-fs")
inherits(FileReader, Reader)

function FileReader (props) {
// console.error(" FR create", props.path, props.size, new Error().stack)
// console.error(" FR create", props._path, props.size, new Error().stack)
var me = this
if (!(me instanceof FileReader)) throw new Error(
"FileReader must be called as constructor.")
Expand All @@ -34,7 +34,7 @@ function FileReader (props) {

FileReader.prototype._getStream = function () {
var me = this
, stream = me._stream = fs.createReadStream(me.path, me.props)
, stream = me._stream = fs.createReadStream(me._path, me.props)

if (me.props.blksize) {
stream.bufferSize = me.props.blksize
Expand All @@ -55,7 +55,7 @@ FileReader.prototype._getStream = function () {

stream.on("end", function () {
if (me._paused || me._buffer.length) {
// console.error("FR Buffering End", me.path)
// console.error("FR Buffering End", me._path)
me._buffer.push(EOF)
me._read()
} else {
Expand All @@ -64,20 +64,18 @@ FileReader.prototype._getStream = function () {

if (me._bytesEmitted !== me.props.size) {
me.error("Didn't get expected byte count\n"+
"type: " + me.type + "\n"+
"path: " + me.path + "\n" +
"expect: "+me.props.size + "\n" +
"actual: "+me._bytesEmitted)
}
})

stream.on("close", function () {
if (me._paused || me._buffer.length) {
// console.error("FR Buffering Close", me.path)
// console.error("FR Buffering Close", me._path)
me._buffer.push(CLOSE)
me._read()
} else {
// console.error("FR close 1", me.path)
// console.error("FR close 1", me._path)
me.emit("close")
}
})
Expand All @@ -87,36 +85,36 @@ FileReader.prototype._getStream = function () {

FileReader.prototype._read = function () {
var me = this
// console.error("FR _read", me.path)
// console.error("FR _read", me._path)
if (me._paused) {
// console.error("FR _read paused", me.path)
// console.error("FR _read paused", me._path)
return
}

if (!me._stream) {
// console.error("FR _getStream calling", me.path)
// console.error("FR _getStream calling", me._path)
return me._getStream()
}

// clear out the buffer, if there is one.
if (me._buffer.length) {
// console.error("FR _read has buffer", me._buffer.length, me.path)
// console.error("FR _read has buffer", me._buffer.length, me._path)
var buf = me._buffer
for (var i = 0, l = buf.length; i < l; i ++) {
var c = buf[i]
if (c === EOF) {
// console.error("FR Read emitting buffered end", me.path)
// console.error("FR Read emitting buffered end", me._path)
me.emit("end")
} else if (c === CLOSE) {
// console.error("FR Read emitting buffered close", me.path)
// console.error("FR Read emitting buffered close", me._path)
me.emit("close")
} else {
// console.error("FR Read emitting buffered data", me.path)
// console.error("FR Read emitting buffered data", me._path)
me.emit("data", c)
}

if (me._paused) {
// console.error("FR Read Re-pausing at "+i, me.path)
// console.error("FR Read Re-pausing at "+i, me._path)
me._buffer = buf.slice(i)
return
}
Expand All @@ -129,7 +127,7 @@ FileReader.prototype._read = function () {

FileReader.prototype.pause = function (who) {
var me = this
// console.error("FR Pause", me.path)
// console.error("FR Pause", me._path)
if (me._paused) return
who = who || me
me._paused = true
Expand All @@ -139,7 +137,7 @@ FileReader.prototype.pause = function (who) {

FileReader.prototype.resume = function (who) {
var me = this
// console.error("FR Resume", me.path)
// console.error("FR Resume", me._path)
if (!me._paused) return
who = who || me
me.emit("resume", who)
Expand Down
5 changes: 2 additions & 3 deletions lib/file-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ FileWriter.prototype._create = function () {
so.mode = Writer.filemode
if (me._old && me._old.blksize) so.bufferSize = me._old.blksize

me._stream = fs.createWriteStream(me.path, so)
me._stream = fs.createWriteStream(me._path, so)

me._stream.on("open", function (fd) {
me.ready = true
Expand All @@ -47,7 +47,7 @@ FileWriter.prototype._create = function () {
me._stream.on("drain", function () { me.emit("drain") })

me._stream.on("close", function () {
// console.error("\n\nFW Stream Close", me.path, me.size)
// console.error("\n\nFW Stream Close", me._path, me.size)
me._finish()
})
}
Expand Down Expand Up @@ -88,7 +88,6 @@ FileWriter.prototype._finish = function () {
if (typeof me.size === "number" && me._bytesWritten != me.size) {
me.error(
"Did not get expected byte count.\n" +
"path: " + me.path + "\n" +
"expect: " + me.size + "\n" +
"actual: " + me._bytesWritten)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/link-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function LinkReader (props) {
// override the _stat method.
LinkReader.prototype._stat = function (currentStat) {
var me = this
fs.readlink(me.path, function (er, linkpath) {
fs.readlink(me._path, function (er, linkpath) {
if (er) return me.error(er)
me.linkpath = me.props.linkpath = linkpath
me.emit("linkpath", linkpath)
Expand Down
6 changes: 3 additions & 3 deletions lib/link-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ LinkWriter.prototype._create = function () {
// there's no good way to read them if we don't already know.
if (hard) return clobber(me, lp, link)

fs.readlink(me.path, function (er, p) {
fs.readlink(me._path, function (er, p) {
// only skip creation if it's exactly the same link
if (p && p === lp) return finish(me)
clobber(me, lp, link)
})
}

function clobber (me, lp, link) {
rimraf(me.path, function (er) {
rimraf(me._path, function (er) {
if (er) return me.error(er)
create(me, lp, link)
})
}

function create (me, lp, link) {
fs[link](lp, me.path, function (er) {
fs[link](lp, me._path, function (er) {
if (er) return me.error(er)
finish(me)
})
Expand Down
26 changes: 16 additions & 10 deletions lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Reader (props, currentStat) {
props = { path: props }
}

if (!props.path) {
if (!props._path) {
me.error("Must provide a path", null, true)
}

Expand Down Expand Up @@ -93,22 +93,28 @@ function Reader (props, currentStat) {
me.depth = props.depth = props.depth || 0
me.parent = props.parent || null
me.root = props.root || (props.parent && props.parent.root) || me
me.path = path.resolve(props.path)

me._path = me.path = path.resolve(props.path)
if (process.platform === "win32" && me._path.length > 200) {
// how DOES one create files on the moon?
me._path = "\\\\?\\" + me.path.replace(/\//g, "\\")
}

me.basename = props.basename = path.basename(me.path)
me.dirname = props.dirname = path.dirname(me.path)

// these have served their purpose, and are now just noisy clutter
props.parent = props.root = null

// console.error("\n\n\n%s setting size to", props.path, props.size)
// console.error("\n\n\n%s setting size to", props._path, props.size)
me.size = props.size
me.filter = typeof props.filter === "function" ? props.filter : null
if (props.sort === "alpha") props.sort = alphasort

// start the ball rolling.
// this will stat the thing, and then call me._read()
// to start reading whatever it is.
// console.error("calling stat", props.path, currentStat)
// console.error("calling stat", props._path, currentStat)
me._stat(currentStat)
}

Expand All @@ -125,13 +131,13 @@ Reader.prototype._stat = function (currentStat) {
, props = me.props
, stat = props.follow ? "stat" : "lstat"

// console.error("Reader._stat", me.path, currentStat)
// console.error("Reader._stat", me._path, currentStat)
if (currentStat) process.nextTick(statCb.bind(null, null, currentStat))
else fs[stat](me.path, statCb)
else fs[stat](me._path, statCb)


function statCb (er, props_) {
// console.error("Reader._stat, statCb", me.path, props_, props_.nlink)
// console.error("Reader._stat, statCb", me._path, props_, props_.nlink)
if (er) return me.error(er)

Object.keys(props_).forEach(function (k) {
Expand All @@ -148,14 +154,14 @@ Reader.prototype._stat = function (currentStat) {
// special little thing for handling hardlinks.
if (type !== "Directory" && props.nlink && props.nlink > 1) {
var k = props.dev + ":" + props.ino
// console.error("Reader has nlink", me.path, k)
if (hardLinks[k] === me.path || !hardLinks[k]) hardLinks[k] = me.path
// console.error("Reader has nlink", me._path, k)
if (hardLinks[k] === me._path || !hardLinks[k]) hardLinks[k] = me._path
else {
// switch into hardlink mode.
type = me.type = me.props.type = "Link"
me.Link = me.props.Link = true
me.linkpath = me.props.linkpath = hardLinks[k]
// console.error("Hardlink detected, switching mode", me.path, me.linkpath)
// console.error("Hardlink detected, switching mode", me._path, me.linkpath)
// Setting __proto__ would arguably be the "correct"
// approach here, but that just seems too wrong.
me._stat = me._read = LinkReader.prototype._read
Expand Down
Loading

0 comments on commit 3e5d171

Please sign in to comment.