[Scummvm-devel] PORTERS: Fixing an old flaw in various FSNode implementations

Max Horn max at quendi.de
Wed Sep 3 19:01:19 CEST 2008


Am 03.09.2008 um 16:46 schrieb Max Horn:

[...]
>
> The advantage of all this: No more worrying about adding/removing
> trailing (back)slashes from paths. Normalized paths don't have a
> trailing (back)slash, period.


I was a bit eager when I wrote this (and in some of the recent changes  
I made): Of course there is one exception, at least on Unix: The root  
node "/" does have a trailing slash. While we could change it so that  
the root node is represented by an empty path (at least internally),  
this would (currently) lead to a clash with relative paths...


Relative paths is a subject I wanted to hear opinions on anyway: Right  
now, it is possible to use FSNodes on relative paths. That is, I could  
do this:

   FilesystemNode node("foo/bar");
   if (node.exists()) { ... }

The problems begin when I use getParent on the above node twice. Our  
current code will do various things, depending on the underlying  
AbstractFSNode implementation; for the POSIX node, with latest SVN it  
should return an invalid node.

Right now the whole situation is a bit fuzzy, and I see two choices:

(1) Make it officially possible to use relative paths.
(2) Forbid relative paths (whatever that means in general). I don't  
think our own codes uses them explicitly, but a user might want to use  
relative paths in his config file, or on the command line (I do that  
sometimes)

For (1), there would be two variants I can think of:

(1a) In the AbstractFSNode constructor, if a relative node is passed  
in, automatically convert it to a absolute note (e.g. for POSIX, by  
prepending the result of getcwd() to it).

(1b) In getParent(), if doing getParent() on a relative node where we  
can't go up anymore, return a node referring to the CWD (current  
working dir).

Approach 1a also makes it possible to compare FSNodes in more cases;  
the drawback is that it converts all paths to absolute ones, but the  
user might prefer to keep a relative one in his config file (should we  
care?!?)... I am torn what to do right now, any suggestions / opinions?


Cheers,
Max




More information about the Scummvm-devel mailing list