Skip to content
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

Improve Windows support by retrying rename to fix slow network drives #130

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
- 5.3
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
- run: composer install
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
Expand All @@ -45,4 +45,5 @@ jobs:
if: ${{ matrix.php >= 7.1 && matrix.php < 8.0 }}
- run: composer require symfony/console:^3.0 --dry-run --working-dir=tests/install-as-dep
if: ${{ matrix.php >= 5.5 && matrix.php < 8.0 }}
- run: composer install --dry-run --working-dir=tests/install-as-dep
- run: cd tests/install-as-dep && composer install && php query.php
- run: cd tests/install-as-dep && php -d phar.readonly=0 vendor/bin/phar-composer build . query.phar && php query.phar
9 changes: 7 additions & 2 deletions src/Phar/PharComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public function build()
// failure to write will emit a warning (ignore) and throw an (uncaught) exception
try {
@$targetPhar->stopBuffering();
$targetPhar = null;
} catch (\PharException $e) {
throw new \RuntimeException('Unable to write phar: ' . $e->getMessage());
}
Expand All @@ -223,8 +224,12 @@ public function build()
$this->log(' - Overwriting existing file <info>' . $target . '</info> (' . $this->getSize($target) . ')');
}

if (rename($tmp, $target) === false) {
throw new \UnexpectedValueException('Unable to rename temporary phar archive to "'.$target.'"');
if (@rename($tmp, $target) === false) {
// retry renaming after sleeping to give slow network drives some time to flush data
sleep(5);
if (rename($tmp, $target) === false) {
throw new \UnexpectedValueException('Unable to rename temporary phar archive to "'.$target.'"');
}
}

$time = max(microtime(true) - $time, 0);
Expand Down
3 changes: 3 additions & 0 deletions tests/install-as-dep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/query.phar
/vendor/
8 changes: 7 additions & 1 deletion tests/install-as-dep/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
"require-dev": {
"clue/phar-composer": "*@dev"
},
"bin": [
"query.php"
],
"repositories": [
{
"type": "path",
"url": "../../"
"url": "../../",
"options": {
"symlink": false
}
}
]
}
5 changes: 5 additions & 0 deletions tests/install-as-dep/query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

require __DIR__ . '/vendor/autoload.php';

echo 'Answer: 42' . PHP_EOL;