forked from alibaba/funcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-support.js
48 lines (40 loc) · 1.27 KB
/
docker-support.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const fs = require('fs-extra');
const path = require('path');
const _ = require('lodash');
const USER_HOME = require('os').homedir();
const defaultFileSharingPaths = [
'/Users',
'/Volumes',
'/private',
'/tmp'
];
async function getSharedPathsOfDockerForMac() {
const settingsPath = path.join(USER_HOME, 'Library/Group Containers/group.com.docker/settings.json');
const fileData = await fs.readFile(settingsPath, 'utf8');
const settings = JSON.parse(fileData);
if (settings.hasOwnProperty('filesharingDirectories')) {
return settings.filesharingDirectories;
}
return defaultFileSharingPaths;
}
async function findPathsOutofSharedPaths(mounts) {
const dockerSharedPaths = await getSharedPathsOfDockerForMac();
let pathsOutofSharedPaths = [];
for (let mount of mounts) {
if (_.isEmpty(mount)) { continue; }
const mountPath = mount.Source;
let isMountPathSharedToDocker = false;
for (let dockerSharedPath of dockerSharedPaths) {
if (mountPath.startsWith(dockerSharedPath)) {
isMountPathSharedToDocker = true;
break;
}
}
if (!isMountPathSharedToDocker) {
pathsOutofSharedPaths.push(mountPath);
}
}
return pathsOutofSharedPaths;
}
module.exports = { findPathsOutofSharedPaths };