Compare commits
	
		
			No commits in common. "master" and "v1.0.2" have entirely different histories.
		
	
	
		
	
		
							
								
								
									
										30
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								index.js
									
									
									
									
									
								
							| @ -1,25 +1,7 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| var PromiseA; | ||||
| try { | ||||
|   PromiseA = require('bluebird'); | ||||
| } catch(e) { | ||||
|   PromiseA = global.Promise; | ||||
| } | ||||
| 
 | ||||
| var util = require('util'); | ||||
| var promisify = util.promisify || PromiseA.promisify; | ||||
| if (!PromiseA || !promisify) { | ||||
|   throw new Error("DON'T PANIC. Everything is A-OK." | ||||
|     + " However, you're on a really old version of node. All you need to do is `npm install --save bluebird`" | ||||
|     + " (in your project directory, which is probably '" + require('path').dirname(require.main.filename) + "')" | ||||
|     + " and everything will work just fine."); | ||||
| } | ||||
| 
 | ||||
| var fs = require('fs'); | ||||
| var writeFileAsync = promisify(fs.writeFile); | ||||
| var unlinkAsync = promisify(fs.unlink); | ||||
| var renameAsync = promisify(fs.rename); | ||||
| var PromiseA = require('bluebird').Promise; | ||||
| var fs = PromiseA.promisifyAll(require('fs')); | ||||
| var crypto = require('crypto'); | ||||
| 
 | ||||
| function noop() { | ||||
| @ -62,23 +44,23 @@ function create(options) { | ||||
|   , stageAsync: function (filename, data, options) { | ||||
|       var tmpname = tmpnamefn(filename); | ||||
|       //console.log(tmpname);
 | ||||
|       return writeFileAsync(tmpname, data, options).then(function () { | ||||
|       return fs.writeFileAsync(tmpname, data, options).then(function () { | ||||
|         return tmpname; | ||||
|       }); | ||||
|     } | ||||
|   , commitAsync: function (tmpname, filename) { | ||||
|       var bakname = baknamefn(filename); | ||||
|       // this may not exist
 | ||||
|       return unlinkAsync(bakname).then(noop, noop).then(function () { | ||||
|       return fs.unlinkAsync(bakname).then(noop, noop).then(function () { | ||||
|         // this may not exist
 | ||||
|         //console.log(namefn(filename), '->', bakname);
 | ||||
|         return renameAsync(filename, bakname).then(function () { | ||||
|         return fs.renameAsync(filename, bakname).then(function () { | ||||
|           //console.log('created bak');
 | ||||
|         }, noop); | ||||
|       }).then(function () { | ||||
|         // this must be successful
 | ||||
|         //console.log(filename, '->', filename);
 | ||||
|         return renameAsync(tmpname, filename).then(noop, function (err) { | ||||
|         return fs.renameAsync(tmpname, filename).then(noop, function (err) { | ||||
|           //console.error(err);
 | ||||
|           return sfs.revert(filename).then(function () { | ||||
|             return PromiseA.reject(err); | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "safe-replace", | ||||
|   "version": "1.1.0", | ||||
|   "version": "1.0.2", | ||||
|   "description": "A micro-module for safely replacing a file.", | ||||
|   "main": "index.js", | ||||
|   "scripts": { | ||||
| @ -8,7 +8,7 @@ | ||||
|   }, | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
|     "url": "https://git.coolaj86.com/coolaj86/fs-safe-replace.js.git" | ||||
|     "url": "git+https://github.com/coolaj86/node-safe-replace.git" | ||||
|   }, | ||||
|   "keywords": [ | ||||
|     "cluster", | ||||
| @ -23,7 +23,7 @@ | ||||
|   "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)", | ||||
|   "license": "(MIT OR Apache-2.0)", | ||||
|   "bugs": { | ||||
|     "url": "https://git.coolaj86.com/coolaj86/fs-safe-replace.js/issues" | ||||
|     "url": "https://github.com/coolaj86/node-safe-replace/issues" | ||||
|   }, | ||||
|   "homepage": "https://git.coolaj86.com/coolaj86/fs-safe-replace.jse" | ||||
|   "homepage": "https://github.com/coolaj86/node-safe-replace#readme" | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user