diff options
author | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-10-12 22:54:37 +0300 |
---|---|---|
committer | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-10-12 22:54:37 +0300 |
commit | 703e03aba33f234712206769f57717ba7d92d23d (patch) | |
tree | 0041f04ccb75bd5379c764e9fe42249fffe75fc3 /node_modules/dir-compare/src/symlink/loopDetector.js | |
parent | ab6e257e6e9d9a483d7e86f220d8b209a2cd7753 (diff) | |
download | FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.gz FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.zst |
Added export_allowed file to make repository visible in cgit
Diffstat (limited to 'node_modules/dir-compare/src/symlink/loopDetector.js')
-rw-r--r-- | node_modules/dir-compare/src/symlink/loopDetector.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/node_modules/dir-compare/src/symlink/loopDetector.js b/node_modules/dir-compare/src/symlink/loopDetector.js new file mode 100644 index 0000000..0376ebb --- /dev/null +++ b/node_modules/dir-compare/src/symlink/loopDetector.js @@ -0,0 +1,51 @@ +var fs = require('fs') + +/** + * Provides symlink loop detection to directory traversal algorithm. + */ +module.exports = { + detectLoop: function (entry, symlinkCache) { + if (entry && entry.isSymlink) { + var realPath = fs.realpathSync(entry.absolutePath) + if (symlinkCache[realPath]) { + return true + } + } + return false + }, + + initSymlinkCache: function() { + return { + dir1: {}, + dir2: {} + } + }, + + updateSymlinkCache: function(symlinkCache, rootEntry1, rootEntry2, loopDetected1, loopDetected2) { + var symlinkCachePath1, symlinkCachePath2 + if (rootEntry1 && !loopDetected1) { + symlinkCachePath1 = rootEntry1.isSymlink ? fs.realpathSync(rootEntry1.absolutePath) : rootEntry1.absolutePath + symlinkCache.dir1[symlinkCachePath1] = true + } + if (rootEntry2 && !loopDetected2) { + symlinkCachePath2 = rootEntry2.isSymlink ? fs.realpathSync(rootEntry2.absolutePath) : rootEntry2.absolutePath + symlinkCache.dir2[symlinkCachePath2] = true + } + }, + + cloneSymlinkCache: function (symlinkCache) { + return { + dir1: shallowClone(symlinkCache.dir1), + dir2: shallowClone(symlinkCache.dir2) + } + }, +} + +function shallowClone(obj) { + var cloned = {} + Object.keys(obj).forEach(function (key) { + cloned[key] = obj[key] + }) + return cloned +} + |