-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
FileFS::toInternalPath() prepends working directory to absolute path #8
Comments
Hey @j-j-banks I think there is some misunderstood from your side for the purpose of First of all, there is a difference between what you call working directory (which is actually the root path of a FireFS instance), and what FireFS calls a working directory. As FireFS works like a virtual filesystem, it manages its own working directories internally, to make a difference between absolute and relative paths (take a look at the README for example). When you mount a filesystem instance on a directory, FireFS will consider the absolute path to that directory as the internal root path. Since FireFS works as a virtual filesystem, every absolute path you feed to him will be considered absolute from the virtual filesystem, so they will be prepended with the real filesystem absolute path (which is the absolute path to where you created the FireFS instance, a.k.a the internal root path) for internal usage. That's where the For this path conversion thing there are 02 other methods:
Maybe the terms used here are misleading, but this is how to think:
Now coming back to your issue, I don't know the use case which leads you to the usage of that method, but if it's really needed, you should tell FireFS how to reach your directory using an external path, by taking your example (with current working directory FileFS::toIntenralPath('../Docs');
// Result: /Users/dennis/Docs |
Thank you so much for the quick reply; I really appreciate it. In this case, I had the following code: $fs = new FireFS(); // Check if the directory to watch exists The folder /home/dennis/watchme existed. When I ran this code, the process failed with error: Cannot create directory. So in debug mode, I traced the process, and found that although I was passing an absolute path (starting with a directory separator) the value I passed was altered by prepending the current path. Here's a video showing the problem clearly and step-by-step: https://youtu.be/pAV30NxXWpQ What I think you're telling me, is that this does not support truly absolute paths in the same manner as the rest of the world does. That would be a sad shame. For example, if my interpretation is correct, and if I want to watch /home/dennis/a and /usr/local/b, then there's no way to do that within one script, lther than cd / before beginning. |
Hey @j-j-banks, With your example I have now an idea of what you want. Have you tried to use $fs = new FireFS();
// Check if the directory to watch exists
define('WATCH_FOLDER', $fs->toExternalPath('/home/dennis/watchme'));
if (!$fs->exists(WATCH_FOLDER)) {
// If not, create the directory
$fs->mkdir(WATCH_FOLDER);
} This should be able to transform that path to a relative path from the one you created the filesystem (I'm not sure, it's been a while I didn't worked on this 😅) If that method doesn't work I should need to fix it, since it's built for that purpose. |
Sounds perfect. I will check when I return home tomorrow or Monday! Thank you! |
FireFS::toInternalPath prepends working directory (which is confusingly referred to as $this->rootPath) to absolute path.
Example:
Current working directory is /Users/dennis/bin/
FileFS::toIntenralPath('/Users/dennis/Docs')
Result: /Users/dennis/bin/Users/dennis/Docs
To circumvent this, I have modified from line 368 as follows:
// Prepend the root path
if (substr($internalPath, 0, 1) !== DIRECTORY_SEPARATOR) { // Added - Lovelady, 7-Feb-2024 (process was prepending "root path" to absolute path)
$rootPath = $this->rootPath();
if (!empty($rootPath)) {
$internalPath = $this->makePath($rootPath, $internalPath);
}
} // Added - Lovelady, 7-Feb-2024 (process was prepending "root path" to absolute path)
But since I don't necessarily understand all the conditions that this routine might be trying to address, I am not certain this is a fix for all conditions. It would be better to have the source fixed in the official distribution. It was very tempting, for example, to test for (substr($internalPath, 0, 1) !== DIRECTORY_SEPARATOR) and return unchanges on true, right at the top of toInternalPath(), which is where I suspect it actually belongs.
The text was updated successfully, but these errors were encountered: