-
-
Notifications
You must be signed in to change notification settings - Fork 76
Files/FileList: adding the same file twice should not increment FileList::$numFiles
#1150
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
Files/FileList: adding the same file twice should not increment FileList::$numFiles
#1150
Conversation
0b0430a
to
befb62b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rodrigoprimo, nice work!
I've left some small comments and questions in various places, nothing really blocking.
Only real question I have is with regards to the solution applied in the third commit versus the suggestion I left in #1113 (comment)
I've now started wondering if
$numFiles
shouldn't be set just once at the end of the__construct()
method via acount($this->files)
instead of doing the incrementing whenever a new file is being added... ? I'd expect that would solve the issue too.
While I can see that, as the addFile()
method is public
, this wouldn't solve anything for addFile()
when not called from the constructor, I do imagine the above suggestion could simplify the code change for the constructor itself.
Was there a particular reason why you went with a different solution ?
4b3b6ec
to
78ab8ac
Compare
Thanks for your review, @jrfnl!
I did consider your suggestion, but noticed that it did not apply to Besides that, I addressed all the other comments. Could you please take another look when you get a chance? Also, before merging this PR, let me know if you prefer to squash the commits yourself or if you would like me to do it. |
78ab8ac
to
d958137
Compare
Rebased without changes to fix the failing |
@rodrigoprimo As I'm going to need to look at the complete thing again before merging this, feel free to reorganize the commits already when you make your final changes. |
185e384
to
5165510
Compare
Done, this PR is now ready for a final review. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making those updates @rodrigoprimo!
Just one small suggestion to prevent head scratching in the future. Otherwise this looks good to go.
Thanks, @jrfnl. Makes sense to me to add this comment. I just approved your suggestion. |
This is just an initial set of tests. It does not fully cover the FileList::__construct() method.
This is just an initial set of tests. It does not fully cover the FileList::addFile() method.
…List::$numFiles` This commit fixes the `FileList::__construct()` and `FileList::addFile()` methods to ensure that, when there is an attempt to add the same file twice, the `FileList::$numFiles` variable is not incremented. The code was already handling duplicates correctly in the sense that duplicated files were not added to `FileList::$files`. However, `FileList::$numFiles` was being incorrectly incremented. There is some duplicated logic in `FileList::__construct()` and `FileList::addFile()`. I considered refactoring the duplicated code to a private method before adding the check that is added in this commit. I decided not to do it as there are some subtle differences between the logic in the two methods. `FileList::__construct()` always sets the value of an entry in the `FileList::$files` to `null` and the key to whatever is returned by `SplFileInfo::getPathname()`. While `FileList::addFile()` sets the value of an entry in the `FileList::$files` to `null` or an object passed to the method and the key to the path passed to the method. I decided to leave this refactor to remove the duplication to the future and focus this commit on fixing the issue with handling duplicated files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rodrigoprimo ! I'll squash that last commit into the first and will merge this once the build has passed.
a1cd435
to
fa148a9
Compare
Description
This PR fixes the
FileList::__construct()
andFileList::addFile()
methods to ensure that, when there is an attempt to add the same file twice, theFileList::$numFiles
variable is not incremented. This behavior was causing a fatal error when using the--parallel
option and passing the same file twice (see #1113).The code was already handling duplicates correctly in the sense that duplicated files were not added to
FileList::$files
. However,FileList::$numFiles
was being incorrectly incremented.This PR also includes some basic tests for
FileList::__construct()
andFileList::addFile()
in separate commits.Suggested changelog entry
Fixed: fatal error when using the
--parallel
option and passing the same file twiceRelated issues/external references
Fixes #1113
Additional notes
There is some duplicated logic in
FileList::__construct()
andFileList::addFile()
. I considered refactoring the duplicated code to a private method before adding the check that is added in this commit. I decided not to do it as there are some subtle differences between the logic in the two methods that make the refactor not straightforward.FileList::__construct()
always sets the value of an entry in theFileList::$files
tonull
and the key to whatever is returned bySplFileInfo::getPathname()
. WhileFileList::addFile()
sets the value of an entry in theFileList::$files
tonull
or an object passed to the method, and the key to the path passed to the method.I decided to leave this refactor to remove the duplication to the future and focus this commit on fixing the issue with handling duplicated files. I believe it will be necessary to write additional tests for this class and also incorporate more defensive code.
Types of changes
PR checklist