Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skipSubdirs still compares the directories themselves #77

Open
hudsonm62 opened this issue Apr 27, 2024 · 2 comments
Open

skipSubdirs still compares the directories themselves #77

hudsonm62 opened this issue Apr 27, 2024 · 2 comments

Comments

@hudsonm62
Copy link

hudsonm62 commented Apr 27, 2024

As the title says, skipSubdirs still compares directories themselves. Not sure what the intended functionality is, but I expected it to be ignored all together in the compare.

This extends gliviu/dir-compare-cli#1

File structure

.\compare
│   d_file2.txt
│   m_file1.txt
│   m_file3.txt
│
├───directory1
│       d_file2.txt
│       m_file1.txt
│       m_file3.txt
│
└───directory2
        d_file2.txt
        m_file1.txt
        m_file3.txt

Reproduction Script

const diff = require("dir-compare")

const options = {
  skipSubdirs: true,
}

const input = {
  path1: "./compare/directory1",
  path2: "./compare/",
}

diff
  .compare(input.path1, input.path2, options)
  .then((results) => {
    results.diffSet.forEach((d) => {
      const differenceString = `${d.relativePath}${d.name1} (${d.type1}): ${d.state} - ${d.name2} (${d.type2})`
      console.log(differenceString)
    })
  })
  .catch((error) => {
    throw new Error(error)
  })

Outputs

> node .\test.js

\undefined (missing): right - directory1 (directory)
\undefined (missing): right - directory2 (directory)
\d_file2.txt (file): equal - d_file2.txt (file)     
\m_file1.txt (file): equal - m_file1.txt (file)     
\m_file3.txt (file): equal - m_file3.txt (file)

With skipSubdirs: false

> node .\test.js
\undefined (missing): right - directory1 (directory)
\directory1undefined (missing): right - d_file2.txt (file)
\directory1undefined (missing): right - m_file1.txt (file)
\directory1undefined (missing): right - m_file3.txt (file)
\undefined (missing): right - directory2 (directory)
\directory2undefined (missing): right - d_file2.txt (file)
\directory2undefined (missing): right - m_file1.txt (file)
\directory2undefined (missing): right - m_file3.txt (file)
\d_file2.txt (file): equal - d_file2.txt (file)
\m_file1.txt (file): equal - m_file1.txt (file)
\m_file3.txt (file): equal - m_file3.txt (file)

edit- typo

@gliviu
Copy link
Owner

gliviu commented Apr 30, 2024

Thanks for the detailed report. I'll take a look these days.

@gliviu
Copy link
Owner

gliviu commented May 4, 2024

Starting with v5.0, skipSubdirs has a different behavior.

Lets consider these directories.

d1
  subdir1
    a3.txt
  a1.txt (size=1)
  a2.txt (size=1)
d2
  subdir1
    a4.txt
  subdir2
    a5.txt
  a1.txt (size=1)
  a2.txt (size=1)

And this code.

import { compareSync } from "dir-compare";
const options = {
  skipSubdirs: true
}
const path1 = "d1"
const path2 = "d2"
const results = compareSync(path1, path2, options)
results.diffSet?.forEach((d) => {
  const differenceString = `${d.relativePath}${d.name1} (${d.type1}): ${d.state} - ${d.name2} (${d.type2})`
  console.log(differenceString)
})

In v5+ the comparison between d1 and d2 using skipSubdirs, correctly ignores any inner directories.

/a1.txt (file): equal - a1.txt (file)
/a2.txt (file): equal - a2.txt (file)

In v4.x the inner directories are included in the comparison, without their content.

/subdir1 (directory): equal - subdir1 (directory)
/undefined (missing): right - subdir2 (directory)
/a1.txt (file): equal - a1.txt (file)
/a2.txt (file): equal - a2.txt (file)

gliviu added a commit that referenced this issue May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants