Skip to content

FileSystem::rename() fix renaming file/directory if only case changes #155

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

Merged
merged 3 commits into from
Feb 6, 2018

Conversation

Ciki
Copy link
Contributor

@Ciki Ciki commented Nov 21, 2017

  • bug fix? yes
  • new feature? no
  • BC break? no

When trying to rename file/directory itself in order to change only case of filename (eg. test.php to Test.php), the process fails as the method first deletes the desired file(name) prior to renaming it .. thus it deletes the original file/dir that was about to be renamed.
This change prevents that case.

When trying to rename file/directory itself in order to change only case of filename (eg. `test.php` to `Test.php`), the process fails as the method first [deletes](https://github.com/nette/utils/blob/master/src/Utils/FileSystem.php#L110) the desired file(name) prior to renaming it .. thus it deletes the original file/dir that was about to be renamed.
@dg
Copy link
Member

dg commented Nov 21, 2017

Good point. However, checking whether the files are the same should be done differently (I don't know how). For compatibility between NTFS and Linux.

@Ciki
Copy link
Contributor Author

Ciki commented Nov 21, 2017

@dg you think realpath could do the work properly? I added new commit prior to seeing your comment

@dg
Copy link
Member

dg commented Nov 21, 2017

Maybe compare stat?

@Ciki
Copy link
Contributor Author

Ciki commented Nov 22, 2017

I think the realpath should do the work properly but I am no expert on this. Any use case where it might break? I can add the stat comparison but not sure when it can fail and return false thus skipping the removal of dest file (eg. when FALSE is returned for both different source and dest file)

@dg
Copy link
Member

dg commented Nov 23, 2017

Realpath should do the work, I didn’t test it. It this case there shouldn’t be lower().

@Ciki
Copy link
Contributor Author

Ciki commented Nov 23, 2017

@dg updated

@dg
Copy link
Member

dg commented Nov 24, 2017

Did you test it? I am not sure that realpath really works this way.

@Ciki
Copy link
Contributor Author

Ciki commented Nov 26, 2017

@dg I did.. on OS preventing same filenames differing in case only, like Windows, realpath correctly transforms eg Test.php and teSt.php to test.php if test.php exists. On the other hand on Linux, where filenames can differ in case, it returns the original and correct names. As far as I can tell and test, it works correctly

@dg
Copy link
Member

dg commented Nov 28, 2017

Great. But it seems that it breaks test…

@Ciki
Copy link
Contributor Author

Ciki commented Dec 11, 2017

@dg should I remove the failing test altogether? As the failing rename method cannot be actually tested IMO - according to php.net spec If renaming a directory and newname exists, this function will emit a warning. but this case never occurs

@dg dg merged commit f12927d into nette:master Feb 6, 2018
@dg
Copy link
Member

dg commented Feb 6, 2018

Thanks, merged

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.

2 participants