diff --git a/services/clsi/app/js/UrlCache.js b/services/clsi/app/js/UrlCache.js index e8ee10dc67..23afafaaa8 100644 --- a/services/clsi/app/js/UrlCache.js +++ b/services/clsi/app/js/UrlCache.js @@ -35,8 +35,12 @@ module.exports = UrlCache = { if (error != null) { return callback(error) } - return UrlCache._copyFile(pathToCachedUrl, destPath, function (error) { + return fs.copyFile(pathToCachedUrl, destPath, function (error) { if (error != null) { + logger.error( + { err: error, from: pathToCachedUrl, to: destPath }, + 'error copying file from cache' + ) return UrlCache._clearUrlDetails(project_id, url, () => callback(error) ) @@ -163,25 +167,6 @@ module.exports = UrlCache = { )}` }, - _copyFile(from, to, _callback) { - if (_callback == null) { - _callback = function (error) {} - } - const callbackOnce = function (error) { - if (error != null) { - logger.error({ err: error, from, to }, 'error copying file from cache') - } - _callback(error) - return (_callback = function () {}) - } - const writeStream = fs.createWriteStream(to) - const readStream = fs.createReadStream(from) - writeStream.on('error', callbackOnce) - readStream.on('error', callbackOnce) - writeStream.on('close', callbackOnce) - return writeStream.on('open', () => readStream.pipe(writeStream)) - }, - _clearUrlFromCache(project_id, url, callback) { if (callback == null) { callback = function (error) {} diff --git a/services/clsi/test/unit/js/UrlCacheTests.js b/services/clsi/test/unit/js/UrlCacheTests.js index 2b991245a9..40652c5899 100644 --- a/services/clsi/test/unit/js/UrlCacheTests.js +++ b/services/clsi/test/unit/js/UrlCacheTests.js @@ -27,7 +27,7 @@ describe('UrlCache', function () { 'settings-sharelatex': (this.Settings = { path: { clsiCacheDir: '/cache/dir' } }), - fs: (this.fs = {}) + fs: (this.fs = { copyFile: sinon.stub().yields() }) } })) }) @@ -248,7 +248,6 @@ describe('UrlCache', function () { beforeEach(function () { this.cachePath = 'path/to/cached/url' this.destPath = 'path/to/destination' - this.UrlCache._copyFile = sinon.stub().callsArg(2) this.UrlCache._ensureUrlIsInCache = sinon .stub() .callsArgWith(3, null, this.cachePath) @@ -268,7 +267,7 @@ describe('UrlCache', function () { }) it('should copy the file to the new location', function () { - return this.UrlCache._copyFile + return this.fs.copyFile .calledWith(this.cachePath, this.destPath) .should.equal(true) })