feature(ischanged) change dir to tmp

This commit is contained in:
coderaiser 2014-08-15 07:18:16 -04:00
parent 4cabdd5172
commit 118423cf14

View file

@ -1,22 +1,56 @@
(function() {
'use strict';
var
DIR_JSON = __dirname + '/../../json/',
var fs = require('fs'),
os = require('os'),
fs = require('fs'),
Util = require('../util'),
time = require('./timem'),
NAME_SHORT = DIR_JSON + 'changes',
NAME = NAME_SHORT + '.json',
WIN = process.platform === 'win32',
Times = {};
Times = {},
Util.exec.try(function() {
Times = require(NAME_SHORT);
DIR = getDir() || __dirname + '/../../json/',
NAME_SHORT = DIR + 'changes',
NAME = NAME_SHORT + '.json';
makeDir(function(error) {
if (!error)
Util.exec.try(function() {
Times = require(NAME_SHORT);
});
});
function getDir() {
var dir;
if (os.tmpdir) {
dir = os.tmpdir();
dir += '/ischanged';
if (!WIN)
dir += '-' + process.getuid() + '/';
}
return dir;
}
function makeDir(callback) {
var ANY_MASK = 0,
umask = process.umask(ANY_MASK);
fs.mkdir(DIR, function(error) {
process.umask(umask);
if (error && error.code === 'EEXIST')
callback();
else
callback(error);
});
}
module.exports = function(name, callback) {
var readTime = Times[name];