Ejemplo n.º 1
0
		fs.rename(oldPath, statePath, function(err){
			
			//Unable to set current state, restore previous current state
			if(err){
				fs.rename(tempPath, statePath, function(err){
					cb(false);
					return;
				});
				
				return;
			}
			
			//Make temp file no different than any other backup state file
			fs.rename(tempPath, oldPath, function(err){
			
				if(err){
					cb(false);
					return;
				}
			
				cb(statePath);
				return;
			});
		
		});
Ejemplo n.º 2
0
 fs.exists(dir + '/' + new_filename, function(ex3) {
     if (ex3) {
         rep.status = 0;
         rep.error = i18nm.__("cannot_rename_same");
         return res.send(JSON.stringify(rep));
     }
     // Go ahead
     fs.rename(dir + '/' + old_filename, dir + '/' + new_filename, function(cr) {
         if (cr) {
             rep.status = 0;
             rep.error = i18nm.__("rename_error");
             return res.send(JSON.stringify(rep));
         }
         var fn = crypto.createHash('md5').update(old_filename).digest('hex');
         async.series([
             function(callback) {
                 fs.exists(dir + '/___thumb_' + fn + '.jpg', function(ex) {
                     if (ex) {
                         var nf = crypto.createHash('md5').update(new_filename).digest('hex');
                         fs.rename(dir + '/___thumb_' + fn + '.jpg', dir + '/___thumb_' + nf + '.jpg', function(err) {
                             callback();
                         });
                     } else {
                         callback();
                     }
                 });
             },
             function(callback) {
                 rep.status = 1;
                 res.send(JSON.stringify(rep));
                 return callback();
             }
         ]);
     });
 });
Ejemplo n.º 3
0
 async.eachSeries(LocalEpisodes, function (name, callback) {
   
   var ep = parseEpData(name);
   
   ep.newName = buildNewName(ep);
   
   console.log(ep.name, '>', ep.newName);
   
   if (cfg.move || cfg.copy) {
     
     if (!cfg.destDir) {
      fail("No destination directory") 
     }
     
     if (cfg.move) {
       fs.rename(
         path.join(cfg.srcDir, ep.name),
         path.join(cfg.destDir, ep.newName),
         callback
       );
     }
     else if (cfg.copy) {
       fs.copy(
         path.join(cfg.srcDir, ep.name),
         path.join(cfg.destDir, ep.newName), 
         callback
       );
     }
     
   }
   else {
     callback(null);
   }
   
 }, function (err) {
Ejemplo n.º 4
0
  createPhoto: function(req, res) {
                 var image = req.files.photo.image;
                 var title = req.body.photo.title || image.name;
                 var description = req.body.photo.description || '';

                 var extension = path.extname(image.name);
                 if (extension==='..')
                   extension = '';
                 var filename = mongoose.Types.ObjectId() + extension;
                 var qualifiedFilename = path.join(applicationRoot, 'public', 'photos', filename);

                 fs.rename(image.path,
                           qualifiedFilename,
                           function(err) {
                             logger.error(err);
                             if (err)
                               return res.send(400);

                             Photo.create({
                                            title: title,
                                            description: description,
                                            path: qualifiedFilename,
                                            modified: Date.now()
                                          },
                                          function (err) {
                                            if (err)
                                              return res.send(400);
                                            res.redirect('/');
                                          });
                           });

                 },
module.exports.updatePhoto = function (req, res){
    var file = req.files.file;
    var userId = req.body.userId;
    
    console.log("User " + userId + " is submitting " , file);
    var uploadDate = new Date();
   
    
    var tempPath = file.path;
    var targetPath = path.join(__dirname, "../../uploads/" + userId + uploadDate + file.name);
    var savePath = "/uploads/" + userId + uploadDate + file.name;
    
    fs.rename(tempPath, targetPath, function (err){
        if (err){
            console.log(err)
        } else {
            User.findById(userId, function(err, userData){
                var user = userData;
                user.image = savePath;
                user.save(function(err){
                    if (err){
                        console.log("failed save")
                        res.json({status: 500})
                    } else {
                        console.log("save successful");
                        
                        res.json({status: 200})
                    }
                })
            })
        }
    })
};
module.exports.updatePhoto = (req, res) => {
  var file = req.files.file;
  var userId = req.body.userId;

  var uploadDate = new Date().toISOString();
  uploadDate = uploadDate.replace('.','');
  uploadDate = uploadDate.replace('-','');
  uploadDate = uploadDate.replace(':','');

  const savePath =  `../../upload/${userId}${uploadDate}${file.name}`
  const tempPath = file.path;
  const targetPath  = path.join(__dirname, savePath);


  fs.rename(tempPath, targetPath, (err) => {
     if (err) {
        throw err;
     }
     User.findById(userId, (err, data) => {
       var user = new User(data);
       user.image = savePath;
       user.save( (e) => {
         if (e){
           res.json({status: 500});
         }

         console.log('save successful');
         res.json({status: 200});
       });

     });
  });
};
Ejemplo n.º 7
0
 }).on('rename', function(data){
     var filename = path.join(config.path, data.filename);
     fs.rename(filename, path.join(path.dirname(filename), data.name), function(err){
         if (err)
             console.error(err);
     });
 }).on('touch', function(data){
Ejemplo n.º 8
0
 return BluebirdPromise.map(files, file => {
   const [fileName, ext] = file.split('.');
   const [root] = fileName.split('_');
   const newName = `${root}${suffix}${(ext) ? `.${ext}` : ''}`;
   return fs.rename(`${process.cwd()}/${workingDir}/${dir}/${file}`,
     `${process.cwd()}/${workingDir}/${dir}/${newName}`);
 });
Ejemplo n.º 9
0
 fs.rename(deployTemp, timestamped, function(err) {
   if (err) {
     return end(err);
   }
   fs.rename(join(timestamped, 'index.html'), index, function(err) {
     if (err) {
       return end(err);
     }
     // replaces links from main html file
     fs.readFile(index, 'utf8', function(err, content) {
       if (err) {
         return end(err);
       }
       specs = [{
         pattern: /<\s*script([^>]*)data-main\s*=\s*(["'])(.*(?=\2))\2([^>]*)src\s*=\s*(["'])(.*(?=\5))\5/gi,
         replace: '<script$1data-main="' + timestamp + '/$3"$4src="' + timestamp + '/$6"'
       },{
         pattern: /<\s*script([^>]*)src\s*=\s*(["'])(.*(?=\2))\2([^>]*)data-main\s*=\s*(["'])(.*(?=\5))\5/gi,
         replace: '<script$1src="' + timestamp + '/$3"$4data-main="' + timestamp + '/$6"'
       },{
         pattern: /<\s*link([^>]*)href\s*=\s*(["'])(.*(?=\2))\2/gi,
         replace: '<link$1href="' + timestamp + '/$3"'
       }];
       specs.forEach(function(spec) {
         content = content.replace(spec.pattern, spec.replace);
       });
       fs.writeFile(index, content, end);
     });
   });
 });
Ejemplo n.º 10
0
NpLaravelGenerator.prototype.setupLaravel = function () {
  this.log.write().ok('Setting up Laravel config');
  var cb = this.async();

  // copy env file
  fs.rename('./.env.example', './.env', logError);

  // edit env file (environment, db, debug settings)
  fs.readFile('./.env', 'utf8', function (err,data) {
    if (err) {
      errors.push('Cannot open .env file for editing.');
    }

    data = data.replace(/APP_ENV=local/g, 'APP_ENV=development');
    data = data.replace(/DB_DATABASE=homestead/g, 'DB_DATABASE='+settings.dbName);
    data = data.replace(/DB_USERNAME=homestead/g, 'DB_USERNAME='******'DB_PASSWORD='******'./.env', data, 'utf8', function (err,data) {
      if (err) {
        errors.push('Error editing .env file with correct values.');
      }
    });
  });

  // php artisan create key
  var res = shell.exec('php artisan key:generate', {silent: true});
  if (res.code !== 0) {
      errors.push('Error generating app key.');
  } else {
    settings.createAppKey = false;
  }

  cb();
};
Ejemplo n.º 11
0
 moveFileToCache(filename, target, cb, onSuccess) {
   debug('moving', filename, 'from', this.cache, 'to', target);
   fs.rename(path.join(this.cache, filename), target, err => {
     if (err) return cb(err);
     onSuccess(cb);
   });
 }
Ejemplo n.º 12
0
	function(cb) {
		fs.rename(
			pathBuild + '/css',
			pathBuild + '/_css',
			cb
		);
	}
            fs.rename(source, target , function(error) {
                if (error) return callback(error);

                fs.rename(
                    source.replace('.epub', '.jpg'), // TODO alle extensions berücksichtigen!   options.bookExtensions
                    target.replace('.epub', '.jpg'), callback);
            });
Ejemplo n.º 14
0
    return new Y.Promise(function(resolve, reject) {
        var finalDir,
            outDirPlatform,
            target;

        target = path.resolve(program.dist + '/laut' + '_' + value.platform +  '_' + version + '.tar.gz');

        outDirPlatform = outputDir + path.sep + 'out' + path.sep + value.platform;

        fs.mkdirsSync(outDirPlatform);

        finalDir = outDirPlatform + path.sep + 'laut_' + value.platform + '_' + version;

        fs.rename(value.dirToWrap, finalDir, function(error) {
            if (error) {
                reject(error);
            }
            else {
                new targz().compress(finalDir, target, function(error) {
                    if (error) {
                        reject(error);
                    }
                    else {
                        console.log('The compression of: ' + target + ' has ended!');

                        resolve(value);
                    }
                });
            }
        });
    });
Ejemplo n.º 15
0
  fs.mkdirs(path.dirname(newPath), function (error) {
    if (error) {
      return callback(error);
    }

    fs.rename(oldPath, newPath, callback);
  });
Ejemplo n.º 16
0
			form.on('end', function () {
				var newfilename = req.user._id.toString() + '-' + CoreUtilities.makeNiceName(path.basename(returnFile.name, path.extname(returnFile.name))) + path.extname(returnFile.name),
					newfilepath = path.join(fullUploadDir, newfilename);
				fs.rename(returnFile.path, newfilepath, function (err) {
					if (err) {
						CoreController.handleDocumentQueryErrorResponse({
							err: err,
							res: res,
							req: req
						});
					}
					else {
						returnFileObj.attributes = {};
						returnFileObj.size = returnFile.size;
						returnFileObj.filename = returnFile.name;
						returnFileObj.assettype = returnFile.type;
						returnFileObj.path = newfilepath;
						returnFileObj.locationtype = 'local';
						returnFileObj.attributes.periodicDirectory = uploadDirectory;
						returnFileObj.attributes.periodicPath = path.join(uploadDirectory, newfilename);
						returnFileObj.fileurl = returnFileObj.attributes.periodicPath.replace('/public', '');
						returnFileObj.attributes.periodicFilename = newfilename;
						// console.log('returnFileObj',returnFileObj);
						req.controllerData.fileData = returnFileObj;
						next();
					}
				});
			});
module.exports.uploadPhoto = function(req, res) {
  var file = req.files.file;
  var userId = req.body.userId;

  // console.log("User - " + userId + " is submitting ", file);

  var newDate = new Date();
  //isostring so we can manipulate date later


  var tmpPath = file.path;
  var targetPath = path.join(__dirname, "../uploads/" + userId + file.name);
  var savePath = "/uploads/" + userId  + file.name;

  fs.rename(tmpPath, targetPath, function(err){

    if(err) {
      console.log(err)
    } else {
      // console.log("file moved")
      User.findById(userId, function(err, userData){
        var user = userData;
        user.image = savePath;
        user.save(function(err){
          if(err) {
            res.json({status: 500})
          } else {
            res.json({status: 200})
          }
        })
      })
    }

  })
}
Ejemplo n.º 18
0
function RenameFile(filename, newname, callback, sync) {
	if (!sync)
		fs.rename(filename, newname, callback);
	else {
		fs.renameSync(filename, newname);
		callback();
	}
}
Ejemplo n.º 19
0
			movebackup: function (cb) {
				if (useExistingBackup) {
					cb(null, 'skip move directory, useExistingBackup');
				}
				else {
					fs.rename(originalbackupuploadpath, fixedbackuppath, cb);
				}
			},
Ejemplo n.º 20
0
					.on("end",function  () {
						fs.rename('upfile/' + mp4Id + '_.mp4', 'upfile/' + mp4Id + '.mp4', function(err) {
							if (err) throw err;
							//console.log("end! " + mp4Id);
							app.onEnd( mp4Id );
							_next();
						});
					})
Ejemplo n.º 21
0
 function(cb_) {
   fs.rename(path.join(tmp_dist_path, 
                       'Breach.app', 'Contents', 'Resources', 
                       'shell', 'breach.icns'), 
             path.join(tmp_dist_path, 
                       'Breach.app', 'Contents', 'Resources', 
                       'app.icns'),
                       cb_);
 },
Ejemplo n.º 22
0
 fs.exists(dir + '/___thumb_' + fn + '.jpg', function(ex) {
     if (ex) {
         var nf = crypto.createHash('md5').update(new_filename).digest('hex');
         fs.rename(dir + '/___thumb_' + fn + '.jpg', dir + '/___thumb_' + nf + '.jpg', function(err) {
             callback();
         });
     } else {
         callback();
     }
 });
Ejemplo n.º 23
0
    async.each(Data.posts, function(post, callback) {

            fs.rename(Dir.publicPosts + post.url + "/index.md", Dir.publicPosts + post.url + "/index.html", function(err) {
                if (err) return console.error(err);

                fs.writeFile(Dir.publicPosts + post.url + "/index.html", fn(post), function(err) {
                    if (err) return console.log(err);
                });
            });
        },
Ejemplo n.º 24
0
 tarball.extractTarballDownload(dependency.dist.tarball, temp, dir, {}, function (err) {
     fs.rename(path.join(dir, 'package'), path.join(dir, dependency.name), function (err) {
         if (err) {
             callBack(err);
         } else {
             fs.remove(temp);
             downloadDependency(dest, dependencies, callBack, index);
         }
     });
 });
Ejemplo n.º 25
0
                    easyimg.convert({src: destPath + newFileName, dst: destPath + newFileName + ".png", quality:100}).then(function (file) {

                        fs.rename( destPath + newFileName + ".png", 
                             destPath + newFileName, function(err) {
                            
                            done(err,result);
                            
                        });
                                                        
                    });
Ejemplo n.º 26
0
    this.getDirPath(function (err, path) {
        if (err) return next(err);

        if (that.type == 'folder')
            fs.mkdir(path, next);
        else
            fs.rename(that.meta.tmp, path, function (err) {
                that.meta.tmp = undefined;
                next(err);
            });
    });
Ejemplo n.º 27
0
	RenameLocalFileTask.prototype.renameLocalFile = function(options) {
		var fs = require('fs-extra');
		options.onBegin();
		fs.rename(options.oldPath, options.newPath, function (error) {
			if (!error) {
				options.onComplete();
			} else {
				options.onError(err);
			}
		});
	};
Ejemplo n.º 28
0
server.put(commandRegEx, function (req, res, next) {
    
    // Check request
    checkReq(config, req, res);
    
    // Set path
    var path = config.base + "/" + req.params[2];
    
    switch (req.params[1]) {
        
        // Rename a file or directory
        case "rename":
            
            var base_path = getBasePath(path);
            
            fs.rename(path,base_path + "/" + req.params.name, function () {
                resSuccess(null, res);
            });
            
            break;
        
        // Saves contents to a file
        case "save":
            
            // Make sure it exists
            if (fs.existsSync(path)) {
                // Make sure it's a file
                if (!fs.lstatSync(path).isDirectory()) {
                    // Write (binary encoding supports text and binary files)
                    fs.writeFile(path, req.params.data, 'binary', function(err) {
                        if(err) {
                            resError(107, err, res);
                        } else {
                            resSuccess(null, res);
                        }
                    });
                } else {
                    resError(106, null, res);
                }
            } else {
                resError(105, null, res);
            }
            
            break;
        
            
        default:
            // Unknown command
            resError(100, null, res);
    }
    
    return next();
    
});
Ejemplo n.º 29
0
                            function(image) {
                                
                                fs.rename(destPathTmp + ".png", 
                                    destPathTmp, function(err) {
                                    
                                    done(err,result);
                                    
                                });
                                

                            },
Ejemplo n.º 30
0
		  		fs.readFile(file, 'utf-8', function(err, data){
		  			if(err) console.log(err);
		  			else{
		  				data = data.replace(reg1, matchers[str1]);
		  				data = data.replace(reg2, matchers[str2]);
		  				newName = file.replace(reg1, matchers[str1]);
		  				fs.writeFileSync(file, data);
		  				fs.rename(file, newName, function(err){
		  					if(err) console.log(err);
		  				});
		  			}
		  		});