Socket
Socket
Sign inDemoInstall

vinyl-fs

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vinyl-fs - npm Package Compare versions

Comparing version 2.3.1 to 2.3.2

CHANGELOG.md

2

lib/dest/index.js

@@ -35,3 +35,3 @@ 'use strict';

if (typeof sourcemapOpt === 'boolean') {
sourcemapOpt = { sourcemaps: sourcemapOpt };
sourcemapOpt = {};
}

@@ -38,0 +38,0 @@

'use strict';
var fs = require('fs');
var writeDir = require('./writeDir');

@@ -9,3 +8,3 @@ var writeStream = require('./writeStream');

function writeContents(writePath, file, cb) {
function writeContents(writePath, file, callback) {
// If directory then mkdirp it

@@ -33,30 +32,13 @@ if (file.isDirectory()) {

if (file.isNull()) {
return complete();
return written();
}
function complete(err) {
cb(err, file);
}
// This is invoked by the various writeXxx modules when they've finished
// writing the contents.
function written(err) {
if (isErrorFatal(err)) {
return complete(err);
return callback(err);
}
if (!file.stat || typeof file.stat.mode !== 'number' || file.symlink) {
return complete();
}
fs.stat(writePath, function(err, st) {
if (err) {
return complete(err);
}
var currentMode = (st.mode & parseInt('0777', 8));
var expectedMode = (file.stat.mode & parseInt('0777', 8));
if (currentMode === expectedMode) {
return complete();
}
fs.chmod(writePath, expectedMode, complete);
});
callback(null, file);
}

@@ -63,0 +45,0 @@

'use strict';
var fs = require('graceful-fs');
var fo = require('../../fileOperations');
var futimes = require('../../futimes');
function writeBuffer(writePath, file, written) {
var opt = {
mode: file.stat.mode,
flag: file.flag,
};
function writeBuffer(writePath, file, cb) {
var stat = file.stat;
fo.writeFile(writePath, file.contents, opt, onWriteFile);
fs.open(writePath, file.flag, stat.mode, function(err, fd) {
if (err) {
return cb(err);
function onWriteFile(writeErr, fd) {
if (writeErr) {
return fo.closeFd(writeErr, fd, written);
}
fs.write(fd, file.contents, 0, file.contents.length, 0, function(error) {
if (error) {
return complete(error);
}
futimes(fd, stat, complete);
});
fo.updateMetadata(fd, file, onUpdate);
}
// Cleanup
function complete(err1) {
fs.close(fd, function(err2) {
cb(err1 || err2);
});
}
});
function onUpdate(statErr, fd) {
fo.closeFd(statErr, fd, written);
}
}
module.exports = writeBuffer;
'use strict';
var fs = require('graceful-fs');
var mkdirp = require('mkdirp');
function writeDir(writePath, file, cb) {
mkdirp(writePath, file.stat.mode, cb);
var fo = require('../../fileOperations');
function writeDir(writePath, file, written) {
var mkdirpOpts = {
mode: file.stat.mode,
fs: fs,
};
mkdirp(writePath, mkdirpOpts, onMkdirp);
function onMkdirp(mkdirpErr) {
if (mkdirpErr) {
return written(mkdirpErr);
}
fs.open(writePath, 'r', onOpen);
}
function onOpen(openErr, fd) {
// If we don't have access, just move along
if (isInaccessible(openErr)) {
return fo.closeFd(null, fd, written);
}
if (openErr) {
return fo.closeFd(openErr, fd, written);
}
fo.updateMetadata(fd, file, onUpdate);
}
function onUpdate(statErr, fd) {
fo.closeFd(statErr, fd, written);
}
}
function isInaccessible(err) {
if (!err) {
return false;
}
if (err.code === 'EACCES') {
return true;
}
return false;
}
module.exports = writeDir;

@@ -5,55 +5,51 @@ 'use strict';

var fo = require('../../fileOperations');
var streamFile = require('../../src/getContents/streamFile');
var futimes = require('../../futimes');
function writeStream(writePath, file, cb) {
var stat = file.stat;
var outStream;
var outFD;
function writeStream(writePath, file, written) {
var opt = {
mode: file.stat.mode,
flag: file.flag,
};
fs.open(writePath, 'w', file.stat.mode, function(err, fd) {
if (err) {
cb(err);
}
var outStream = fs.createWriteStream(writePath, opt);
outFD = fd;
outStream = fs.createWriteStream(null, { fd: fd });
file.contents.once('error', complete);
file.contents.once('end', readStreamEnd);
outStream.once('error', complete);
outStream.once('finish', complete);
file.contents.once('error', complete);
file.contents.once('end', readStreamEnd);
outStream.once('error', complete);
outStream.once('finish', complete);
// Streams are piped with end disabled, this prevents the
// WriteStream from closing the file descriptor after all
// data is written.
file.contents.pipe(outStream, { end: false });
// Streams are piped with end disabled, this prevents the
// WriteStream from closing the file descriptor after all
// data is written.
file.contents.pipe(outStream, { end: false });
});
function readStreamEnd() {
streamFile(file, {}, function(error) {
if (error) {
return complete(error);
}
streamFile(file, complete);
}
futimes(outFD, stat, function(error) {
if (error) {
return complete(error);
}
function end(propagatedErr) {
outStream.end(onEnd);
// All finished with WriteStream, close and clean up
outStream.end();
});
});
function onEnd(endErr) {
written(propagatedErr || endErr);
}
}
// Cleanup
function complete(err) {
function complete(streamErr) {
file.contents.removeListener('error', complete);
file.contents.removeListener('end', readStreamEnd);
if (outStream) {
outStream.removeListener('error', complete);
outStream.removeListener('finish', complete);
outStream.removeListener('error', complete);
outStream.removeListener('finish', complete);
if (streamErr) {
return end(streamErr);
}
cb(err);
if (typeof outStream.fd !== 'number') {
return end();
}
fo.updateMetadata(outStream.fd, file, end);
}

@@ -60,0 +56,0 @@ }

@@ -5,12 +5,17 @@ 'use strict';

function writeSymbolicLink(writePath, file, cb) {
function writeSymbolicLink(writePath, file, written) {
// TODO handle symlinks properly
fs.symlink(file.symlink, writePath, function(err) {
if (err && err.code !== 'EEXIST') {
return cb(err);
if (isFatalError(err)) {
return written(err);
}
cb(null, file);
written();
});
}
function isFatalError(err) {
return (err && err.code !== 'EEXIST');
}
module.exports = writeSymbolicLink;

@@ -57,3 +57,7 @@ 'use strict';

// Mkdirp the folder the file is going in
mkdirp(writeFolder, options.dirMode, function(err) {
var mkdirpOpts = {
mode: options.dirMode,
fs: fs,
};
mkdirp(writeFolder, mkdirpOpts, function(err) {
if (err) {

@@ -60,0 +64,0 @@ return cb(err);

@@ -8,2 +8,7 @@ 'use strict';

function streamFile(file, opt, cb) {
if (typeof opt === 'function') {
cb = opt;
opt = {};
}
var filePath = file.path;

@@ -10,0 +15,0 @@

'use strict';
var path = require('path');
var assign = require('object-assign');

@@ -16,2 +17,17 @@ var through2 = require('through2');

function normalizePath(options) {
function normalize(globFile, enc, cb) {
// TODO: probably move this somewhere
// Ref https://github.com/gulpjs/vinyl/issues/80
var normalizedFile = assign({}, globFile, {
path: path.normalize(globFile.path),
});
cb(null, normalizedFile);
}
return through2.obj(options, normalize);
}
function createFile(globFile, enc, cb) {

@@ -40,2 +56,3 @@ cb(null, new File(globFile));

var outputStream = globStream
.pipe(normalizePath(options))
.pipe(resolveSymlinks(options))

@@ -42,0 +59,0 @@ .pipe(through2.obj(opt, createFile));

{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "2.3.1",
"version": "2.3.2",
"homepage": "http://github.com/wearefractal/vinyl-fs",

@@ -18,4 +18,6 @@ "repository": "git://github.com/wearefractal/vinyl-fs.git",

"gulp-sourcemaps": "^1.5.2",
"is-buffer": "^1.1.2",
"is-valid-glob": "^0.3.0",
"lazystream": "^1.0.0",
"lodash.isequal": "^4.0.0",
"merge-stream": "^1.0.0",

@@ -29,2 +31,3 @@ "mkdirp": "^0.5.0",

"through2-filter": "^2.0.0",
"vali-date": "^1.0.0",
"vinyl": "^1.0.0"

@@ -34,5 +37,8 @@ },

"buffer-equal": "^0.0.1",
"default-resolution": "^1.0.1",
"del": "^2.2.0",
"eslint": "^1.10.3",
"eslint-config-gulp": "^2.0.0",
"expect": "^1.14.0",
"github-changes": "^1.0.1",
"istanbul": "^0.3.0",

@@ -51,3 +57,5 @@ "istanbul-coveralls": "^1.0.1",

"test": "npm run lint && mocha",
"coveralls": "istanbul cover _mocha && istanbul-coveralls"
"cover": "istanbul cover _mocha",
"coveralls": "npm run cover && istanbul-coveralls",
"changelog": "github-changes -o gulpjs -r vinyl-fs -b master -f ./CHANGELOG.md --order-semver --use-commit-body"
},

@@ -54,0 +62,0 @@ "engines": {

@@ -146,2 +146,7 @@ <p align="center">

Once the file is written to disk, an attempt is made to determine if the `stat.mode`, `stat.mtime` and `stat.atime` of the [vinyl] `File` object differ from the file on the filesystem.
If they differ and the running process owns the file, the corresponding filesystem metadata is updated.
If they don't differ or the process doesn't own the file, the attempt is skipped silently.
__This functionality is disabled on Windows operating systems or any other OS that doesn't support `process.getuid` or `process.geteuid` in node. This is due to Windows having very unexpected results through usage of `fs.fchmod` and `fs.futimes`.__
If the file has a `symlink` attribute specifying a target path, then a symlink will be created.

@@ -151,3 +156,3 @@

- `cwd`, `base`, and `path` will be overwritten to match the folder.
- `stat.mode` will be overwritten if you used a mode parameter.
- `stat` will be updated to match the file on the filesystem.
- `contents` will have it's position reset to the beginning if it is a stream.

@@ -154,0 +159,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc