let getFileSize=async function (filePath) { let size=0; if(!filePath) { return size; } let bExist=await (existAsync(filePath)); if(bExist) { let obj=await (fsAsync.statAsync(con.filePath+filePath.replace(/\//g,path.sep))); if(obj) { size+=obj.size; } } return size; }
test('index.find no cache', function (t) { return fs.statAsync(CACHE).then(() => { throw new Error('expected cache directory') }).catch(err => { t.assert(err, 'cache directory does not exist') return index.find(CACHE, 'whatever') }).then(info => { t.ok(!info, 'if there is no cache dir, behaves like a cache miss') }) })
const recursive = directory => fs.readdirAsync(directory).filter(file => { return (file.indexOf('.') !== 0) && (file !== 'index.js'); }).map(file => { file = path.join(directory, file); return fs.statAsync(file).then(stat => stat.isDirectory() ? recursive(file) : file); }).reduce((a, b) => a.concat(b), [])
async function exists (filename) { try { const stats = await statAsync(filename) return stats.isDirectory() || stats.isFile() } catch (e) { return false } }
test('move a file', function (t) { const fixture = new Tacks(Dir({ src: File('foo') })) fixture.create(testDir) return moveFile('src', 'dest').then(() => { return fs.readFileAsync('dest', 'utf8') }).then(data => { t.equal(data, 'foo', 'file data correct') return fs.statAsync('src').catch(err => { t.ok(err, 'src read error') t.equal(err.code, 'ENOENT', 'src does not exist') }) }) })
var recursiveReaddir = function(root, options) { let items = fs.readdirAsync(root) for(let i in options.filters) items = items.filter(options.filters[i]) return items.map(function(f) { var path = p.join(root, f) return fs.statAsync(path) .then(function(stat) { let depth = root.replace(options.root, '').split(p.sep).length if(depth > options.maxDepth) return path if(stat.isDirectory()) { return recursiveReaddir(path, options) } return path }) .catch(gracefulCatch(root, path)) }).then(function(paths) { paths.push(root) return [].concat.apply([], paths) }) }
test('does not clobber existing files', function (t) { const fixture = new Tacks(Dir({ src: File('foo'), dest: File('bar') })) fixture.create(testDir) return moveFile('src', 'dest').then(() => { return fs.readFileAsync('dest', 'utf8') }).then(data => { t.equal(data, 'bar', 'conflicting file left intact') return fs.statAsync('src').catch(err => { t.ok(err, 'src read error') t.equal(err.code, 'ENOENT', 'src file still deleted') }) }) })
return fs.statAsync(path) .then(function(stat) { if(stat.isDirectory()) {
readdirAsync(path) .then(entities => { return Promise.all( entities .map(it => `${path}/${it}`) .map(it => statAsync(it) .then(stat => [ it, stat ]) ) ) }, err => { if (err.code !== 'ENOENT') { throw err } logger.error(`directory '${path}' doesn't exist, skipping...`) return [] }) .then(res => { return Promise.all( res.filter(it => it[1].isDirectory()) .map(it => this.loadApp(it[0]) .catch(err => { logger.error('Unexpected error on loading app', it[0], err.stack) }) ) ) })
return Promise.join(fs.statAsync(path), utils.pathInfo(path), function(stat, info) { if(stat.isDirectory()) { return next(new HTTPError('Downloading a directory is not possible', 400))
var packageJson = JSON.parse(data) executablePath = path.join(appDir, _.get(packageJson, 'main')) return statAsync(executablePath) }) .then(stat => {
unlinkFiles(runId) { const fullPath = path.join(this.appDirectory, 'input', this.clientId, runId); return statAsync(fullPath).then((stats) => { return stats.isDirectory(); })
test('does not error if destination file is open', function (t) { const fixture = new Tacks(Dir({ src: File('foo'), dest: File('bar') })) fixture.create(testDir) return fs.openAsync('dest', 'r+').then(fd => { return moveFile('src', 'dest').then(() => { return fs.closeAsync(fd) }).then(() => { return fs.readFileAsync('dest', 'utf8') }).then(data => { t.equal(data, 'bar', 'destination left intact') return fs.statAsync('src').catch(err => { t.ok(err, 'src read error') t.equal(err.code, 'ENOENT', 'src does not exist') }) }) }) })
const recursive = directory => fs.readdirAsync(directory).filter(file => { return (file.indexOf('.') !== 0) && (file !== 'incoming.js') && (file !== 'incoming_packet.js'); }).map(file => { file = path.join(directory, file); return fs.statAsync(file).then(stat => stat.isDirectory() ? recursive(file) : file); }).reduce((a, b) => a.concat(b), [])