mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
feature(ischanged) change dir to tmp
This commit is contained in:
parent
4cabdd5172
commit
118423cf14
1 changed files with 42 additions and 8 deletions
|
|
@ -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];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue