Debian Codegraph @

lib/dest/write-contents/write-dir.js

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 'use strict';
2
3 var fs = require('graceful-fs');
4
5 var mkdirp = require('fs-mkdirp-stream/mkdirp');
6
7 var fo = require('../../file-operations');
8
9 function writeDir(file, optResolver, onWritten) {
10 mkdirp(file.path, file.stat.mode, onMkdirp);
11
12 function onMkdirp(mkdirpErr) {
13 if (mkdirpErr) {
14 return onWritten(mkdirpErr);
15 }
16
17 fs.open(file.path, 'r', onOpen);
18 }
19
20 function onOpen(openErr, fd) {
21 // If we don't have access, just move along
22 if (isInaccessible(openErr)) {
23 return fo.closeFd(null, fd, onWritten);
24 }
25
26 if (openErr) {
27 return fo.closeFd(openErr, fd, onWritten);
28 }
29
30 fo.updateMetadata(fd, file, onUpdate);
31
32 function onUpdate(updateErr) {
33 fo.closeFd(updateErr, fd, onWritten);
34 }
35 }
36
37 }
38
39 function isInaccessible(err) {
40 if (!err) {
41 return false;
42 }
43
44 if (err.code === 'EACCES') {
45 return true;
46 }
47
48 return false;
49 }
50
51 module.exports = writeDir;