1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

On Windows, implement "Filesystem::copyFile()" with "copy()"

Summary:
Ref T13562. Currently, "Filesystem::copyFile()" uses "copy", which doesn't work now that we no longer invoke "cmd.exe" by default.

Use "copy()" instead.

Note that this whole function is probably nonsense, but I'll follow up on T13562.

Test Plan:
  - Created a standalone script which runs "Filesystem::copyFile()".
    - Before: failed to copy any file.
    - After: succesfully copied normal files.
    - After: failed to copy a file over an existing directory with a reasonable error.
    - After: failed to copy a file over itself with a reasonable error.

Maniphest Tasks: T13562

Differential Revision: https://secure.phabricator.com/D21643
This commit is contained in:
epriestley 2021-03-22 11:35:55 -07:00
parent cc23551a7d
commit f0f95e5b26

View file

@ -269,7 +269,29 @@ final class Filesystem extends Phobject {
self::assertReadable($from); self::assertReadable($from);
if (phutil_is_windows()) { if (phutil_is_windows()) {
execx('copy /Y %s %s', $from, $to); $trap = new PhutilErrorTrap();
$ok = @copy($from, $to);
$err = $trap->getErrorsAsString();
$trap->destroy();
if (!$ok) {
if (strlen($err)) {
throw new FilesystemException(
$to,
pht(
'Failed to copy file from "%s" to "%s": %s',
$from,
$to,
$err));
} else {
throw new FilesystemException(
$to,
pht(
'Failed to copy file from "%s" to "%s".',
$from,
$to));
}
}
} else { } else {
execx('cp -p %s %s', $from, $to); execx('cp -p %s %s', $from, $to);
} }