-
Notifications
You must be signed in to change notification settings - Fork 61
Add uniqueness to GitCheckoutRevisionToTemporaryPath to avoid collisions when checking out the same revision from/to #58
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
Add uniqueness to GitCheckoutRevisionToTemporaryPath to avoid collisions when checking out the same revision from/to #58
Conversation
…ons when checking out the same revision from/to
…ranch (i.e. in the `push` build)
|
||
public function __construct(?callable $uniquenessFunction = null) | ||
{ | ||
if ($uniquenessFunction === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can simply use ??
on the assignment
|
||
if (file_exists($checkoutDirectory) || is_dir($checkoutDirectory)) { | ||
throw new RuntimeException(sprintf( | ||
'Tried to check out revision %s to directory %s which already exists', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put quotes around the %s
here. Also: exception type seems to be incorrect. Can we use our own please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So little point in writing up a specific exception here: the chances of this happening are so slim given each directory is always unique...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use an assertion then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find an assertion like fileNotExists
or directoryNotExists
etc., hence why I wrote that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do like Assert::that(file_exists($dir))->false();
or something?
I think you can `Assert::that($path)->not()->directory()` and the same for
files.
…On Wed, 2 May 2018, 11:20 James Titcumb, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/Git/GitCheckoutRevisionToTemporaryPath.php
<#58 (comment)>
:
> */
public function remove(CheckedOutRepository $checkedOutRepository) : void
{
(new Process(['rm', '-rf', (string) $checkedOutRepository]))->mustRun();
}
+
+ /**
+ * @throws RuntimeException
+ */
+ private function generateTemporaryPathFor(Revision $revision) : string
+ {
+ $uniquePathGenerator = $this->uniquenessFunction;
+ $checkoutDirectory = sys_get_temp_dir() . '/api-compare-' . $uniquePathGenerator((string) $revision . '_');
+
+ if (file_exists($checkoutDirectory) || is_dir($checkoutDirectory)) {
+ throw new RuntimeException(sprintf(
+ 'Tried to check out revision %s to directory %s which already exists',
Can do like Assert::that(file_exists($dir))->false(); or something?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakJv6HNVouyrZuwE0LwVWuSGvWdMWks5tuXpigaJpZM4TvCSx>
.
|
There's no negation thing AFAIK :s |
a98c462
to
5f20b6b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #53
Maybe a little over engineered, but I think this is fairly bulletproof now 😁 at least we have tests!