diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 049bc62..39a3608 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -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 diff --git a/src/Phar/PharComposer.php b/src/Phar/PharComposer.php index 69f584a..bf3467c 100644 --- a/src/Phar/PharComposer.php +++ b/src/Phar/PharComposer.php @@ -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()); } @@ -223,8 +224,12 @@ public function build() $this->log(' - Overwriting existing file ' . $target . ' (' . $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); diff --git a/tests/install-as-dep/.gitignore b/tests/install-as-dep/.gitignore new file mode 100644 index 0000000..070e2f2 --- /dev/null +++ b/tests/install-as-dep/.gitignore @@ -0,0 +1,3 @@ +/composer.lock +/query.phar +/vendor/ diff --git a/tests/install-as-dep/composer.json b/tests/install-as-dep/composer.json index e1bc438..5b69f75 100644 --- a/tests/install-as-dep/composer.json +++ b/tests/install-as-dep/composer.json @@ -5,10 +5,16 @@ "require-dev": { "clue/phar-composer": "*@dev" }, + "bin": [ + "query.php" + ], "repositories": [ { "type": "path", - "url": "../../" + "url": "../../", + "options": { + "symlink": false + } } ] } diff --git a/tests/install-as-dep/query.php b/tests/install-as-dep/query.php new file mode 100644 index 0000000..5364e95 --- /dev/null +++ b/tests/install-as-dep/query.php @@ -0,0 +1,5 @@ +