Skip to content

Commit 3e5d171

Browse files
committed
Try using UNC paths to work around windows weirdness
1 parent bcec334 commit 3e5d171

9 files changed

+79
-67
lines changed

lib/abstract.js

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ function decorate (er, code, me) {
6262
er.path = er.path || me.path
6363
er.fstream_type = me.type
6464
er.fstream_path = me.path
65+
if (me._path !== me.path) {
66+
er.fstream_unc_path = me._path
67+
}
6568
er.fstream_class = me.constructor.name
6669
er.fstream_stack = new Error().stack.split(/\n/).slice(3).map(function (s) {
6770
return s.replace(/^ at /, "")

lib/dir-reader.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function DirReader (props) {
3434

3535
DirReader.prototype._getEntries = function () {
3636
var me = this
37-
fs.readdir(me.path, function (er, entries) {
37+
fs.readdir(me._path, function (er, entries) {
3838
if (er) return me.error(er)
3939
me._entries = entries
4040
me._length = entries.length
@@ -58,7 +58,7 @@ DirReader.prototype._read = function () {
5858

5959
me._index ++
6060
if (me._index >= me._length) {
61-
// console.error(" DR End/close", me.path)
61+
// console.error(" DR End/close", me._path)
6262
me.emit("end")
6363
me.emit("close")
6464
return
@@ -67,7 +67,7 @@ DirReader.prototype._read = function () {
6767
// ok, handle this one, then.
6868

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

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

156156
me._paused = false
157-
// console.error("DR Emit Resume", me.path)
157+
// console.error("DR Emit Resume", me._path)
158158
me.emit("resume", who)
159159
if (me._paused) {
160-
// console.error("DR Re-paused", me.path)
160+
// console.error("DR Re-paused", me._path)
161161
return
162162
}
163163

lib/dir-writer.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function DirWriter (props) {
3232

3333
DirWriter.prototype._create = function () {
3434
var me = this
35-
mkdir(me.path, Writer.dirmode, function (er) {
35+
mkdir(me._path, Writer.dirmode, function (er) {
3636
if (er) return me.error(er)
3737
// ready to start getting entries!
3838
me.ready = true
@@ -56,7 +56,7 @@ DirWriter.prototype.end = function () {
5656
DirWriter.prototype.add = function (entry) {
5757
var me = this
5858

59-
// console.error("\tadd", entry.path, "->", me.path)
59+
// console.error("\tadd", entry._path, "->", me._path)
6060
collect(entry)
6161
if (!me.ready || me._currentEntry) {
6262
me._buffer.push(entry)
@@ -90,7 +90,7 @@ DirWriter.prototype._process = function () {
9090
}
9191

9292
me._processing = true
93-
// console.error("DW Entry", entry.path)
93+
// console.error("DW Entry", entry._path)
9494

9595
me.emit("entry", entry)
9696

@@ -99,8 +99,8 @@ DirWriter.prototype._process = function () {
9999
// don't allow recursive copying
100100
var p = entry
101101
do {
102-
if (p.path === me.root.path || p.path === me.path) {
103-
// console.error("DW Exit (recursive)", entry.basename, me.path)
102+
if (p._path === me.root._path || p._path === me._path) {
103+
// console.error("DW Exit (recursive)", entry.basename, me._path)
104104
me._processing = false
105105
if (entry._collected) entry.pipe()
106106
return me._process()
@@ -115,12 +115,12 @@ DirWriter.prototype._process = function () {
115115
, type: entry.type
116116
, depth: me.depth + 1 }
117117

118-
var p = entry.path || entry.props.path
118+
var p = entry._path || entry.props._path
119119
if (entry.parent) {
120-
p = p.substr(entry.parent.path.length + 1)
120+
p = p.substr(entry.parent._path.length + 1)
121121
}
122122
// get rid of any ../../ shenanigans
123-
props.path = path.join(me.path, path.join("/", p))
123+
props._path = path.join(me._path, path.join("/", p))
124124

125125
// all the rest of the stuff, copy over from the source.
126126
Object.keys(entry.props).forEach(function (k) {
@@ -132,8 +132,8 @@ DirWriter.prototype._process = function () {
132132
// not sure at this point what kind of writer this is.
133133
var child = me._currentChild = new Writer(props)
134134
child.on("ready", function () {
135-
// console.error("DW Child Ready", child.type, child.path)
136-
// console.error(" resuming", entry.path)
135+
// console.error("DW Child Ready", child.type, child._path)
136+
// console.error(" resuming", entry._path)
137137
entry.pipe(child)
138138
entry.resume()
139139
})

lib/file-reader.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var fs = require("graceful-fs")
1414
inherits(FileReader, Reader)
1515

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

3535
FileReader.prototype._getStream = function () {
3636
var me = this
37-
, stream = me._stream = fs.createReadStream(me.path, me.props)
37+
, stream = me._stream = fs.createReadStream(me._path, me.props)
3838

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

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

6565
if (me._bytesEmitted !== me.props.size) {
6666
me.error("Didn't get expected byte count\n"+
67-
"type: " + me.type + "\n"+
68-
"path: " + me.path + "\n" +
6967
"expect: "+me.props.size + "\n" +
7068
"actual: "+me._bytesEmitted)
7169
}
7270
})
7371

7472
stream.on("close", function () {
7573
if (me._paused || me._buffer.length) {
76-
// console.error("FR Buffering Close", me.path)
74+
// console.error("FR Buffering Close", me._path)
7775
me._buffer.push(CLOSE)
7876
me._read()
7977
} else {
80-
// console.error("FR close 1", me.path)
78+
// console.error("FR close 1", me._path)
8179
me.emit("close")
8280
}
8381
})
@@ -87,36 +85,36 @@ FileReader.prototype._getStream = function () {
8785

8886
FileReader.prototype._read = function () {
8987
var me = this
90-
// console.error("FR _read", me.path)
88+
// console.error("FR _read", me._path)
9189
if (me._paused) {
92-
// console.error("FR _read paused", me.path)
90+
// console.error("FR _read paused", me._path)
9391
return
9492
}
9593

9694
if (!me._stream) {
97-
// console.error("FR _getStream calling", me.path)
95+
// console.error("FR _getStream calling", me._path)
9896
return me._getStream()
9997
}
10098

10199
// clear out the buffer, if there is one.
102100
if (me._buffer.length) {
103-
// console.error("FR _read has buffer", me._buffer.length, me.path)
101+
// console.error("FR _read has buffer", me._buffer.length, me._path)
104102
var buf = me._buffer
105103
for (var i = 0, l = buf.length; i < l; i ++) {
106104
var c = buf[i]
107105
if (c === EOF) {
108-
// console.error("FR Read emitting buffered end", me.path)
106+
// console.error("FR Read emitting buffered end", me._path)
109107
me.emit("end")
110108
} else if (c === CLOSE) {
111-
// console.error("FR Read emitting buffered close", me.path)
109+
// console.error("FR Read emitting buffered close", me._path)
112110
me.emit("close")
113111
} else {
114-
// console.error("FR Read emitting buffered data", me.path)
112+
// console.error("FR Read emitting buffered data", me._path)
115113
me.emit("data", c)
116114
}
117115

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

130128
FileReader.prototype.pause = function (who) {
131129
var me = this
132-
// console.error("FR Pause", me.path)
130+
// console.error("FR Pause", me._path)
133131
if (me._paused) return
134132
who = who || me
135133
me._paused = true
@@ -139,7 +137,7 @@ FileReader.prototype.pause = function (who) {
139137

140138
FileReader.prototype.resume = function (who) {
141139
var me = this
142-
// console.error("FR Resume", me.path)
140+
// console.error("FR Resume", me._path)
143141
if (!me._paused) return
144142
who = who || me
145143
me.emit("resume", who)

lib/file-writer.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ FileWriter.prototype._create = function () {
3333
so.mode = Writer.filemode
3434
if (me._old && me._old.blksize) so.bufferSize = me._old.blksize
3535

36-
me._stream = fs.createWriteStream(me.path, so)
36+
me._stream = fs.createWriteStream(me._path, so)
3737

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

4949
me._stream.on("close", function () {
50-
// console.error("\n\nFW Stream Close", me.path, me.size)
50+
// console.error("\n\nFW Stream Close", me._path, me.size)
5151
me._finish()
5252
})
5353
}
@@ -88,7 +88,6 @@ FileWriter.prototype._finish = function () {
8888
if (typeof me.size === "number" && me._bytesWritten != me.size) {
8989
me.error(
9090
"Did not get expected byte count.\n" +
91-
"path: " + me.path + "\n" +
9291
"expect: " + me.size + "\n" +
9392
"actual: " + me._bytesWritten)
9493
}

lib/link-reader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function LinkReader (props) {
3333
// override the _stat method.
3434
LinkReader.prototype._stat = function (currentStat) {
3535
var me = this
36-
fs.readlink(me.path, function (er, linkpath) {
36+
fs.readlink(me._path, function (er, linkpath) {
3737
if (er) return me.error(er)
3838
me.linkpath = me.props.linkpath = linkpath
3939
me.emit("linkpath", linkpath)

lib/link-writer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ LinkWriter.prototype._create = function () {
3939
// there's no good way to read them if we don't already know.
4040
if (hard) return clobber(me, lp, link)
4141

42-
fs.readlink(me.path, function (er, p) {
42+
fs.readlink(me._path, function (er, p) {
4343
// only skip creation if it's exactly the same link
4444
if (p && p === lp) return finish(me)
4545
clobber(me, lp, link)
4646
})
4747
}
4848

4949
function clobber (me, lp, link) {
50-
rimraf(me.path, function (er) {
50+
rimraf(me._path, function (er) {
5151
if (er) return me.error(er)
5252
create(me, lp, link)
5353
})
5454
}
5555

5656
function create (me, lp, link) {
57-
fs[link](lp, me.path, function (er) {
57+
fs[link](lp, me._path, function (er) {
5858
if (er) return me.error(er)
5959
finish(me)
6060
})

lib/reader.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Reader (props, currentStat) {
2424
props = { path: props }
2525
}
2626

27-
if (!props.path) {
27+
if (!props._path) {
2828
me.error("Must provide a path", null, true)
2929
}
3030

@@ -93,22 +93,28 @@ function Reader (props, currentStat) {
9393
me.depth = props.depth = props.depth || 0
9494
me.parent = props.parent || null
9595
me.root = props.root || (props.parent && props.parent.root) || me
96-
me.path = path.resolve(props.path)
96+
97+
me._path = me.path = path.resolve(props.path)
98+
if (process.platform === "win32" && me._path.length > 200) {
99+
// how DOES one create files on the moon?
100+
me._path = "\\\\?\\" + me.path.replace(/\//g, "\\")
101+
}
102+
97103
me.basename = props.basename = path.basename(me.path)
98104
me.dirname = props.dirname = path.dirname(me.path)
99105

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

103-
// console.error("\n\n\n%s setting size to", props.path, props.size)
109+
// console.error("\n\n\n%s setting size to", props._path, props.size)
104110
me.size = props.size
105111
me.filter = typeof props.filter === "function" ? props.filter : null
106112
if (props.sort === "alpha") props.sort = alphasort
107113

108114
// start the ball rolling.
109115
// this will stat the thing, and then call me._read()
110116
// to start reading whatever it is.
111-
// console.error("calling stat", props.path, currentStat)
117+
// console.error("calling stat", props._path, currentStat)
112118
me._stat(currentStat)
113119
}
114120

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

128-
// console.error("Reader._stat", me.path, currentStat)
134+
// console.error("Reader._stat", me._path, currentStat)
129135
if (currentStat) process.nextTick(statCb.bind(null, null, currentStat))
130-
else fs[stat](me.path, statCb)
136+
else fs[stat](me._path, statCb)
131137

132138

133139
function statCb (er, props_) {
134-
// console.error("Reader._stat, statCb", me.path, props_, props_.nlink)
140+
// console.error("Reader._stat, statCb", me._path, props_, props_.nlink)
135141
if (er) return me.error(er)
136142

137143
Object.keys(props_).forEach(function (k) {
@@ -148,14 +154,14 @@ Reader.prototype._stat = function (currentStat) {
148154
// special little thing for handling hardlinks.
149155
if (type !== "Directory" && props.nlink && props.nlink > 1) {
150156
var k = props.dev + ":" + props.ino
151-
// console.error("Reader has nlink", me.path, k)
152-
if (hardLinks[k] === me.path || !hardLinks[k]) hardLinks[k] = me.path
157+
// console.error("Reader has nlink", me._path, k)
158+
if (hardLinks[k] === me._path || !hardLinks[k]) hardLinks[k] = me._path
153159
else {
154160
// switch into hardlink mode.
155161
type = me.type = me.props.type = "Link"
156162
me.Link = me.props.Link = true
157163
me.linkpath = me.props.linkpath = hardLinks[k]
158-
// console.error("Hardlink detected, switching mode", me.path, me.linkpath)
164+
// console.error("Hardlink detected, switching mode", me._path, me.linkpath)
159165
// Setting __proto__ would arguably be the "correct"
160166
// approach here, but that just seems too wrong.
161167
me._stat = me._read = LinkReader.prototype._read

0 commit comments

Comments
 (0)