source: trip-planner-front/node_modules/fs-extra/lib/empty/index.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 992 bytes
Line 
1'use strict'
2
3const u = require('universalify').fromCallback
4const fs = require('graceful-fs')
5const path = require('path')
6const mkdir = require('../mkdirs')
7const remove = require('../remove')
8
9const emptyDir = u(function emptyDir (dir, callback) {
10 callback = callback || function () {}
11 fs.readdir(dir, (err, items) => {
12 if (err) return mkdir.mkdirs(dir, callback)
13
14 items = items.map(item => path.join(dir, item))
15
16 deleteItem()
17
18 function deleteItem () {
19 const item = items.pop()
20 if (!item) return callback()
21 remove.remove(item, err => {
22 if (err) return callback(err)
23 deleteItem()
24 })
25 }
26 })
27})
28
29function emptyDirSync (dir) {
30 let items
31 try {
32 items = fs.readdirSync(dir)
33 } catch (err) {
34 return mkdir.mkdirsSync(dir)
35 }
36
37 items.forEach(item => {
38 item = path.join(dir, item)
39 remove.removeSync(item)
40 })
41}
42
43module.exports = {
44 emptyDirSync,
45 emptydirSync: emptyDirSync,
46 emptyDir,
47 emptydir: emptyDir
48}
Note: See TracBrowser for help on using the repository browser.