Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.state.forEach(function(name, value) {
var basename; // filename without path.
if (value.file) {
basename = task_parameters.fnRename(path.basename(value.file), task_parameters.prefix, task_parameters.suffix);
} else {
basename = task_parameters.fnRename(name, task_parameters.prefix, task_parameters.suffix);
}
if (!fs.existsSync(path.dirname(task_parameters.dest))) {
var self = this;
mkdirp(path.dirname(task_parameters.dest), function(err) {
self.state.write(path.join(task_parameters.dest, basename), value, function(err) {
if (err) {
return status.emit('failure', 'write', 'Could not write: ' + err);
}
if (!--todo) {
return status.emit('complete', 'write', 'Items written.');
}
}, self);
});
} else {
var self = this;
self.state.write(path.join(task_parameters.dest, basename), value, function(err) {
if (err) {
return status.emit('failure', 'write', 'Could not write: ' + err);
_getItemWriteStream (context, filepath, opts) {
const deferred = Q.defer();
// Create any directories specified in the file's path.
mkdirp.mkdirp(path.dirname(filepath), function (err) {
if (err) {
// Reject the promise if an error occurs when creating a directory.
deferred.reject(err);
} else {
try {
// Resolve the promise with a write stream for the specified local file.
const stream = fs.createWriteStream(filepath);
deferred.resolve(stream);
} catch (err) {
// Reject the promise if an error occurs when creating the stream.
deferred.reject(err);
}
}
});
return deferred.promise;
getItemWriteStream (context, asset, opts) {
const deferred = Q.defer();
const self = this;
// Get the file path for the destination file, creating the working directory if necessary.
const filepath = this.getPath(context, opts) + this.getAssetPath(asset);
mkdirp.mkdirp(path.dirname(filepath), function (err) {
if (err) {
// Reject the promise if an error occurs when creating a directory.
deferred.reject(err);
} else {
// Get the file path for a temporary file based on the resource ID.
const tmppath = self.getPath(context, opts) + asset.resource;
self._getItemWriteStream(context, tmppath, opts)
.then(function (stream) {
stream.on("finish", function () {
// On successful finish, we rename the temporary file to the destination file.
try {
fs.renameSync(tmppath, filepath);
} catch (err) {
utils.logErrors(context, i18n.__("error_resource_rename", {"temp": tmppath, "name": filepath}), err);
}
});
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}
function createAndTestSocket (dir) {
mkdirp(dir, options.mod, function (err) {
if (err) {
return callback(err);
}
options.exists = true;
testSocket();
});
}