From 5af0ec336091a788a90ffbc50b9a17e95df44e32 Mon Sep 17 00:00:00 2001 From: Glowry Date: Mon, 10 Oct 2016 17:44:40 +0800 Subject: [PATCH 1/2] Reader does not work when read hardlink I think the following code must be deleted. Because the hardlink will be read by LinkReader. But the hardlink is just file.Trust me! ``` var handleHardlinks = props.hardlinks !== false // special little thing for handling hardlinks. if (handleHardlinks && type !== 'Directory' && props.nlink && props.nlink > 1) { var k = props.dev + ':' + props.ino // console.error("Reader has nlink", self._path, k) if (hardLinks[k] === self._path || !hardLinks[k]) { hardLinks[k] = self._path } else { // switch into hardlink mode. type = self.type = self.props.type = 'Link' self.Link = self.props.Link = true self.linkpath = self.props.linkpath = hardLinks[k] // console.error("Hardlink detected, switching mode", self._path, self.linkpath) // Setting __proto__ would arguably be the "correct" // approach here, but that just seems too wrong. self._stat = self._read = LinkReader.prototype._read } } ``` --- lib/reader.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/reader.js b/lib/reader.js index 876021f..efcc29c 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -155,25 +155,6 @@ Reader.prototype._stat = function (currentStat) { self.size = props.size var type = getType(props) - var handleHardlinks = props.hardlinks !== false - - // special little thing for handling hardlinks. - if (handleHardlinks && type !== 'Directory' && props.nlink && props.nlink > 1) { - var k = props.dev + ':' + props.ino - // console.error("Reader has nlink", self._path, k) - if (hardLinks[k] === self._path || !hardLinks[k]) { - hardLinks[k] = self._path - } else { - // switch into hardlink mode. - type = self.type = self.props.type = 'Link' - self.Link = self.props.Link = true - self.linkpath = self.props.linkpath = hardLinks[k] - // console.error("Hardlink detected, switching mode", self._path, self.linkpath) - // Setting __proto__ would arguably be the "correct" - // approach here, but that just seems too wrong. - self._stat = self._read = LinkReader.prototype._read - } - } if (self.type && self.type !== type) { self.error('Unexpected type: ' + type) From 59ebf517e79733dd432c40da18344ea712d77704 Mon Sep 17 00:00:00 2001 From: Glowry Date: Mon, 10 Oct 2016 18:01:25 +0800 Subject: [PATCH 2/2] Update reader.js --- lib/reader.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/reader.js b/lib/reader.js index efcc29c..73072df 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -5,7 +5,6 @@ var Stream = require('stream').Stream var inherits = require('inherits') var path = require('path') var getType = require('./get-type.js') -var hardLinks = Reader.hardLinks = {} var Abstract = require('./abstract.js') // Must do this *before* loading the child classes