1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-06 04:41:00 +01:00

[Wilds] Implement a Filesystem::concatenatePaths(...) method

Summary:
Ref T13098. This is mostly for getting sensible results under Windows, hopefully instead of weird mixed paths with both `/` and `\`, at least in more cases.

You can pass in several components like `array('/path/to/something/', '/thing.c')` and they'll be concatenated with exactly one correct separator.

Test Plan: Used this in the new `WorkingCopy` stuff, which doesn't run yet. 💁

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13098

Differential Revision: https://secure.phabricator.com/D19691
This commit is contained in:
epriestley 2018-09-18 12:49:29 -07:00
parent c05bbd7be6
commit 11599cedb6

View file

@ -1047,6 +1047,18 @@ final class Filesystem extends Phobject {
return ($u == $v);
}
public static function concatenatePaths(array $components) {
$components = implode($components, DIRECTORY_SEPARATOR);
// Replace any extra sequences of directory separators with a single
// separator, so we don't end up with "path//to///thing.c".
$components = preg_replace(
'('.preg_quote(DIRECTORY_SEPARATOR).'{2,})',
DIRECTORY_SEPARATOR);
return $components;
}
/* -( Assert )------------------------------------------------------------- */