summaryrefslogtreecommitdiff
path: root/node_modules/dir-compare/src/statistics/statisticsUpdate.js
blob: a1b2312497face2820231f74059e639bc42599d1 (about) (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * Calculates comparison statistics.
 */
module.exports = {
    updateStatisticsBoth: function (entry1, entry2, same, reason, type, statistics, options) {
        same ? statistics.equal++ : statistics.distinct++
        if (type === 'file') {
            same ? statistics.equalFiles++ : statistics.distinctFiles++
        } else if (type === 'directory') {
            same ? statistics.equalDirs++ : statistics.distinctDirs++
        } else if (type === 'broken-link') {
            statistics.brokenLinks.distinctBrokenLinks++
        } else {
            throw new Error('Unexpected type ' + type)
        }

        var isSymlink1 = entry1 ? entry1.isSymlink : false
        var isSymlink2 = entry2 ? entry2.isSymlink : false
        var isSymlink = isSymlink1 || isSymlink2
        if (options.compareSymlink && isSymlink) {
            var symlinks = statistics.symlinks
            if (reason === 'different-symlink') {
                symlinks.distinctSymlinks++
            } else {
                symlinks.equalSymlinks++
            }
        }

    },
    updateStatisticsLeft: function (entry1, type, statistics, options) {
        statistics.left++
        if (type === 'file') {
            statistics.leftFiles++
        } else if (type === 'directory') {
            statistics.leftDirs++
        } else if (type === 'broken-link') {
            statistics.brokenLinks.leftBrokenLinks++
        } else {
            throw new Error('Unexpected type ' + type)
        }

        if (options.compareSymlink && entry1.isSymlink) {
            statistics.symlinks.leftSymlinks++
        }
    },
    updateStatisticsRight: function (entry2, type, statistics, options) {
        statistics.right++
        if (type === 'file') {
            statistics.rightFiles++
        } else if (type === 'directory') {
            statistics.rightDirs++
        } else if (type === 'broken-link') {
            statistics.brokenLinks.rightBrokenLinks++
        } else {
            throw new Error('Unexpected type ' + type)
        }

        if (options.compareSymlink && entry2.isSymlink) {
            statistics.symlinks.rightSymlinks++
        }
    },
}