Skip to content

[Filesystem] deprecate relative paths in makePathRelative() #24202

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

Merged
merged 1 commit into from
Sep 27, 2017

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Sep 14, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets
License MIT
Doc PR

@xabbuh
Copy link
Member Author

xabbuh commented Sep 14, 2017

Our docblock always stated that we expected absolute paths. However, we also had tests for relative paths. Thus, I suggest as a compromise to (silently) keep support for relative paths in Symfony 3 (see #22321) and drop it explicitly in 4.0.

@xabbuh xabbuh force-pushed the deprecate-relative-paths branch from 6226154 to 3a70f82 Compare September 14, 2017 12:38
@ausi
Copy link
Contributor

ausi commented Sep 14, 2017

Is there any reason why relative paths should not be supported?

With #22321 relative paths work perfectly fine without problems, why should the method be limited to absolute paths?

@chalasr
Copy link
Member

chalasr commented Sep 14, 2017

@ausi Because it's called makePathRelative() (which implies that the input is not relative), not correctRelativePath(). It's not its job.

@xabbuh
Copy link
Member Author

xabbuh commented Sep 14, 2017

Additionally, it's not clear to what base a path is relative. Will both paths be treated as being relative to the same directory? What if only one of the input paths is relative. All of this can (depending on the context in which it is used) lead to confusion and even be wrong (because of different perceptions of how the paths should be interpreted).

UPGRADE-4.0.md Outdated
@@ -200,6 +200,7 @@ Filesystem
* The `Symfony\Component\Filesystem\LockHandler` has been removed,
use the `Symfony\Component\Lock\Store\FlockStore` class
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
* support for passing relative paths to `Filesystem::makePathRelative()` has been removed in 4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First letter should be uppercase for consistency, same for UPGRADE-3.3. in 4.0 could be removed also

@ausi
Copy link
Contributor

ausi commented Sep 14, 2017

Because it's called makePathRelative() (which implies that the input is not relative), not correctRelativePath(). It's not its job.

The method description says “Given an existing path, convert it to a path relative to a given starting path.”. I don’t see why “existing path” and “starting path” have to be absolute.

IMO it doesn’t imply that the input is not relative, but it implies that the “existing path” is not relative to the “starting path”.

Additionally, it's not clear to what base a path is relative. Will both paths be treated as being relative to the same directory?

I think it’s obvious that two relative paths would refer to the same base, just as two absolute paths refer to the same root.

All of this can (depending on the context in which it is used) lead to confusion and even be wrong (because of different perceptions of how the paths should be interpreted).

From my point of view makePathRelative('aa/cc', 'bb/cc') returning ./ (as it does in the current version) leads to much more confusion.

@nicolas-grekas
Copy link
Member

small conflict to resolve

@xabbuh xabbuh force-pushed the deprecate-relative-paths branch from 3a70f82 to 893df58 Compare September 18, 2017 08:07
@nicolas-grekas
Copy link
Member

@ausi the confusion also comes from the case where one path is relative, and the other is not: this makes the result of the function context sensitive, thus non-predictable (sensitive to getcwd())
So confirming my +1.

@ausi
Copy link
Contributor

ausi commented Sep 26, 2017

@ausi the confusion also comes from the case where one path is relative, and the other is not

Couldn’t we just disallow this case?
Like so:

if ($this->isAbsolutePath($endPath) !== $this->isAbsolutePath($startPath)) {
    throw new InvalidArgumentException('...');
}

@nicolas-grekas
Copy link
Member

The goal is also to make things easier to maintain. WDYT @xabbuh?

@xabbuh
Copy link
Member Author

xabbuh commented Sep 26, 2017

I would separate responsibilities. If there is need for relative paths, I would add a method that returns the absolute path (probably based on a working directory that can also be passed).

@ausi
Copy link
Contributor

ausi commented Sep 26, 2017

Why should it be harder to maintain? Relative paths work already and are unit tested with #22321.

@xabbuh your suggestion would then result in code like this:

$fs->makePathRelative(
	$fs->getAbsolutePath($endPath, $rootPath), 
	$fs->getAbsolutePath($startPath, $rootPath)
);

instead of just:

$fs->makePathRelative($endPath, $startPath);

It would also require to know the root path of the relative paths. I don’t see the benefit here.

@fabpot
Copy link
Member

fabpot commented Sep 27, 2017

Thank you @xabbuh.

@fabpot fabpot merged commit 893df58 into symfony:3.4 Sep 27, 2017
fabpot added a commit that referenced this pull request Sep 27, 2017
…ive() (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Filesystem] deprecate relative paths in makePathRelative()

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

893df58 deprecate relative paths in makePathRelative()
@xabbuh xabbuh deleted the deprecate-relative-paths branch September 27, 2017 20:36
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants