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

[Fix] Infinite while loop when called on root folder, add tests #29

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

BrettCleary
Copy link

When calling getFirstExistingParentPath on the parent folder of a non-existent root drive on Windows, the while loop proceeds indefinitely, crashing the calling program

This is fixed by early return if one iteration of the loop does not change the parent folder

This also changes the while loop to a for loop proceeding up until the max # of folders (with the same condition to stop as the while loop). This is much less error prone

Tests have been added and two other tests have been modified to run on windows as well

test/__helpers__/mockDependencies.ts Outdated Show resolved Hide resolved
Comment on lines +16 to +20
/**
* Linux max file path length is 4096 characters.
* With / separators and 1 letter folder names, this gives us a max of ~2048 folders to traverse.
* This is much less error prone than a while loop.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This limit is not valid on every file system
https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits

So... I do not know if I want to add that to this loop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a number we can change it to that would accomplish this goal? Or another way to avoid a while loop/provide a failsafe if we miss another edge case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately this is of course your call and I'm happy to revert to the while loop if you would like

test/functions/getFirstExistingParentPath.spec.ts Outdated Show resolved Hide resolved
test/functions/getFirstExistingParentPath.spec.ts Outdated Show resolved Hide resolved
test/functions/getFirstExistingParentPath.spec.ts Outdated Show resolved Hide resolved

test('win32: Gets parent to C:\\HyperPlay', async t => {
const parentPath = normalize('C:\\')
const dependencies = getDependencies(parentPath)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to define the pathSep somewhere here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not following. Is this still relevant after the changes I committed?

test/functions/getFirstExistingParentPath.spec.ts Outdated Show resolved Hide resolved
@BrettCleary BrettCleary changed the title [Fix] Infinite while loop for root windows folders, add tests, make tests cross platform [Fix] Infinite while loop when called on root folder, add tests Dec 15, 2023
@BrettCleary
Copy link
Author

@Alex-D apologies for the windows specific runner tests. it was wrong of me to assume that was a goal of this project.

The main issue is the infinite while loop when called on a root directory, which is platform agnostic and this PR fixes and the new tests confirm this.

I've updated the logic and tests to match what you were doing previously with win32 tests in index.spec.ts

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

Successfully merging this pull request may close these issues.

None yet

2 participants