[wp-trac] [WordPress Trac] #54582: Problem with deleting old files at the end of a core update when the filesystem is case-insensitive
WordPress Trac
noreply at wordpress.org
Sun Dec 5 23:07:05 UTC 2021
#54582: Problem with deleting old files at the end of a core update when the
filesystem is case-insensitive
---------------------------------------+---------------------
Reporter: pbiron | Owner: (none)
Type: defect (bug) | Status: new
Priority: high | Milestone: 5.9
Component: Upgrade/Install | Version:
Severity: major | Resolution:
Keywords: needs-patch needs-testing | Focuses:
---------------------------------------+---------------------
Comment (by pbiron):
Here's what I currently have for the check whether the filesystem is case-
insensitive. I'm thing this could be added as a method to
`WP_Filesystem_Direct`:
{{{
#!php
function is_filesystem_case_insenstive() {
$temp_dir = get_temp_dir();
if ( ! is_dir( $temp_dir) ) {
mkdir( $temp_dir );
}
$mixed_case_filename = tempnam( $temp_dir, 'MixedCase' );
$lower_case_filename = strtolower( $mixed_case_filename );
touch( $lower_case_filename );
$mixed_case_stat = stat( $mixed_case_filename );
$lower_case_stat = stat( $lower_case_filename );
// Compare the Inodes returned by the 2 stat calls: if their the
same, then filesystem is case-insensitive.
$filesystem_case_insensitive = $mixed_case_stat['ino'] ===
$lower_case_stat['ino'];
unlink( $mixed_case_filename );
if ( ! $filesystem_case_insensitive ) {
unlink( $lower_case_filename );
}
return $filesystem_case_insensitive;
}
}}}
It seems to work as expected, but needs some error checking added (e.g.,
test that `tempnam()` and `stat()` succeed). Not yet sure what to do if
those fail, i.e., what should it return in that case.
My thought with comparing the `Inodes` is that is more foolproof than
doing something like a `glob()` and counting the number of results
returned...but I could certainly overthinking it. Would love feedback on
that.
I've tested this in Windows and 2 different linux environments (centos a
public server and centos running within WSL on Windows) and it reports
correctly in all 3 cases. Would love to have someone test in MacOS (both
case-sensitive and case-insensitive configs).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54582#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list