FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FilePath bug?

 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  
Author Message
icibiri



Joined: 30 Mar 2005
Posts: 3
Location: Bratislava, Slovakia

PostPosted: Wed Mar 30, 2005 12:34 pm    Post subject: FilePath bug? Reply with quote

Is this a bug in FilePath class? Notice missing "extension" from base path .

Program:

Code:
import  mango.io.Stdout,
        mango.io.FilePath,
      mango.io.FileSystem;

int main() {
   FilePath base = new FilePath(r"E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7.0");
    FilePath fp = new FilePath("adobecmapfnt07.lst" );
   FilePath spliced = new FilePath(fp.splice(base));
   Stdout ("BASE   : ") (base) (CR);
   Stdout ("FILE   : ") (fp) (CR);
   Stdout ("SPLICED: ") (spliced) (CR);
   return 0;
}


Output:
Code:
BASE   : E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7.0
FILE   : adobecmapfnt07.lst
SPLICED: E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7\adobecmapfnt07.lst
--------------------------------------------------------------------------------^^^
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Mar 30, 2005 2:00 pm    Post subject: Reply with quote

That's a bug, and I'll try to get it fixed tonight.

On the face of it, the 7.0 should be treated as a filename and extension ~ yes? To make the 7.0 part of the path, one would presumably add a trailing path-seperator?

- Kris
Back to top
View user's profile Send private message
icibiri



Joined: 30 Mar 2005
Posts: 3
Location: Bratislava, Slovakia

PostPosted: Wed Mar 30, 2005 2:26 pm    Post subject: Reply with quote

E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7.0 is a directory.
Problem encoutered when traversing filesystem. Resulting filename (E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7\adobecmapfnt07.lst) that was created from base path (E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7.0) and actual file in directory (adobecmapfnt07.lst) was not existing.
I think that problem is that base path (without trailing path separator) is treated like file and this is the reasom why .0 "extension" was ommited from base path.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Mar 30, 2005 3:00 pm    Post subject: Reply with quote

Filepath does not know whether you're feeding it a file or directory. It simply parses out the appropriate parts.

If you add a trailing '\' to the original path, then the whole thing will be treated as a directory instead (rather than parsing the 'file' components), and you will get the result you want.

There's still a bug in the splice() method but, even with that fixed, you'd still need the trailing '\' (because when the bug is fixed, the entire 7.0 will be stripped off).

The short story is this: FilePath is not explicitly for directories, so you must add a trailing path-seperator to make it treat the path purely as a directory. In this case, the path should be:

Code:

r"E:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\7.0\"
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Mar 30, 2005 3:05 pm    Post subject: Reply with quote

Please note that you can do something similar using a MutableFilePath, via setName() and setExt(). But without the trailing '\' in the original path, you'd be overwriting the "7" and the "0" respectively (since those would be treated as the filename and extension if the trailing '\' were not present).

Hope this makes sense?
Back to top
View user's profile Send private message
icibiri



Joined: 30 Mar 2005
Posts: 3
Location: Bratislava, Slovakia

PostPosted: Thu Mar 31, 2005 12:14 am    Post subject: Reply with quote

Thank you for explanation. It is clear.

Just one note. Example filescan.d (located in example directory) is not able handle such case properly. If you scan a directory containing dot in the name, then you will have the same problem I described. Example should be modified to handle it properly.
_________________
-Ivan
Back to top
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Thu Mar 31, 2005 12:35 am    Post subject: Reply with quote

kris wrote:

The short story is this: FilePath is not explicitly for directories, so you must add a trailing path-seperator to make it treat the path purely as a directory.

Is it too nit-picky to correct spelling? 'separator' is what you're going for, and I only bring it up, because it's all over the place in Mango code. Maybe you'd want to get it corrected before too many people have code that uses the misspelled instances?

BA
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu Mar 31, 2005 2:30 am    Post subject: Reply with quote

Oh dear Embarassed

That is rather embarrassing. I'll change it, and add an alias ~ thanks, Brad.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu Mar 31, 2005 2:35 am    Post subject: Reply with quote

icibiri wrote:
Thank you for explanation. It is clear.

Just one note. Example filescan.d (located in example directory) is not able handle such case properly. If you scan a directory containing dot in the name, then you will have the same problem I described. Example should be modified to handle it properly.

Well, after all that, I spent a long time looking at it and you are right ~ it's too much hassle for the user if splice() isn't more flexible. To resolve the issue, I've changed it to treat the basepath as a directory only. This means that you'll get the "7.0" as part of the path as you expected it in the first place. Please try to ignore my lunatic ramblings in the earlier posts.

Sorry about that -- it's been a bad day today ...
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu Mar 31, 2005 2:48 am    Post subject: Reply with quote

All changes checked in, including filepath and corrected spelling ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group