summaryrefslogtreecommitdiff
path: root/node_modules/dir-compare/src/statistics
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/dir-compare/src/statistics')
-rw-r--r--node_modules/dir-compare/src/statistics/statisticsLifecycle.js59
-rw-r--r--node_modules/dir-compare/src/statistics/statisticsUpdate.js62
2 files changed, 121 insertions, 0 deletions
diff --git a/node_modules/dir-compare/src/statistics/statisticsLifecycle.js b/node_modules/dir-compare/src/statistics/statisticsLifecycle.js
new file mode 100644
index 0000000..549ec5e
--- /dev/null
+++ b/node_modules/dir-compare/src/statistics/statisticsLifecycle.js
@@ -0,0 +1,59 @@
+/**
+ * Controls creation/completion of global statistics object.
+ */
+module.exports = {
+ initStats(options) {
+ var symlinkStatistics = undefined
+ if (options.compareSymlink) {
+ symlinkStatistics = {
+ distinctSymlinks: 0,
+ equalSymlinks: 0,
+ leftSymlinks: 0,
+ rightSymlinks: 0,
+ differencesSymlinks: 0,
+ totalSymlinks: 0,
+ }
+ }
+ var brokenLinksStatistics = {
+ leftBrokenLinks: 0,
+ rightBrokenLinks: 0,
+ distinctBrokenLinks: 0,
+ }
+ return {
+ distinct: 0,
+ equal: 0,
+ left: 0,
+ right: 0,
+ distinctFiles: 0,
+ equalFiles: 0,
+ leftFiles: 0,
+ rightFiles: 0,
+ distinctDirs: 0,
+ equalDirs: 0,
+ leftDirs: 0,
+ rightDirs: 0,
+ brokenLinks: brokenLinksStatistics,
+ symlinks: symlinkStatistics,
+ same: undefined
+ }
+ },
+
+ completeStatistics(statistics, options) {
+ statistics.differences = statistics.distinct + statistics.left + statistics.right
+ statistics.differencesFiles = statistics.distinctFiles + statistics.leftFiles + statistics.rightFiles
+ statistics.differencesDirs = statistics.distinctDirs + statistics.leftDirs + statistics.rightDirs
+ statistics.total = statistics.equal + statistics.differences
+ statistics.totalFiles = statistics.equalFiles + statistics.differencesFiles
+ statistics.totalDirs = statistics.equalDirs + statistics.differencesDirs
+ var brokenLInksStats = statistics.brokenLinks
+ brokenLInksStats.totalBrokenLinks = brokenLInksStats.leftBrokenLinks + brokenLInksStats.rightBrokenLinks + brokenLInksStats.distinctBrokenLinks
+ statistics.same = statistics.differences ? false : true
+
+ if (options.compareSymlink) {
+ statistics.symlinks.differencesSymlinks = statistics.symlinks.distinctSymlinks +
+ statistics.symlinks.leftSymlinks + statistics.symlinks.rightSymlinks
+ statistics.symlinks.totalSymlinks = statistics.symlinks.differencesSymlinks + statistics.symlinks.equalSymlinks
+ }
+ }
+
+} \ No newline at end of file
diff --git a/node_modules/dir-compare/src/statistics/statisticsUpdate.js b/node_modules/dir-compare/src/statistics/statisticsUpdate.js
new file mode 100644
index 0000000..a1b2312
--- /dev/null
+++ b/node_modules/dir-compare/src/statistics/statisticsUpdate.js
@@ -0,0 +1,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++
+ }
+ },
+} \ No newline at end of file