You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Matt Benson <gu...@yahoo.com> on 2005/02/18 19:54:22 UTC

FileUtils.normalize

This method will:

    * Uppercase the drive letter if there is one.
    * Remove redundant slashes after the drive spec.
    * Resolve all ./, .\, ../ and ..\ sequences.
    * DOS style paths that start with a drive letter
will have \ as the separator.

Other DOS considerations:

when a drive letter is supplied and there is no
separator immediately following, the meaning is
different.  Supplying the separator here yields the
wrong filename.  In this case the meaning is that the
remaining filename beyond the colon is relative to the
current directory for that drive.  As we resolve . and
.. components of the filename, I think we should be
resolving this to the full path intended.

when a single separator leads the path, the path is
relative to the root of the current directory.  I
think we should be resolving that directory as well to
be pointing to the correct file.

OR it may be that we should detect these conditions as
NOT being absolute pathnames on DOS. 
File.isAbsolute() returns false in these cases. 
However, we should still provide some means of
obtaining the absolute forms of these names as well.

The only reason I bring it up rather than just making
the necessary changes is (1) that there is a choice of
which to do, and (2) that the first alternative will
break existing testcases (Project.testResolveFile at
least).  No idea what the second (possibly more
correct) alternative will break.

Thoughts?

-Matt


		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Matt Benson <gu...@yahoo.com>.
--- Stefan Bodewig <bo...@apache.org> wrote:

> On Fri, 18 Feb 2005, Matt Benson
> <gu...@yahoo.com> wrote:
> 
> > OR it may be that we should detect these
> conditions as
> > NOT being absolute pathnames on DOS. 
> 
> As with most Windows/DOS features I'm pretty much on
> the fence.
> 
> To me it sounds as if marking paths "C:foo"
> non-absolute and modify
> resolveFile to deal with them the way you proposed
> normalizePath to do
> would be the better approach.

I think so too, especially since I opened up
FU.isAbsolutePath() to public access.  Similarly with
Netware... I have worked with older versions of
Netware, and on those VOLUME:PATH or VOLUME:\PATH are
equivalent but not absolute.  VOLUME: is relative to
the current server.  So SERVER\VOLUME:(\)?PATH is
absolute, as is "driveletter-colon-separator."  Can
anyone update my knowledge of Netware file
specification conventions?

Thanks,
Matt
> 
> Stefan
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 18 Feb 2005, Matt Benson <gu...@yahoo.com> wrote:

> OR it may be that we should detect these conditions as
> NOT being absolute pathnames on DOS. 

As with most Windows/DOS features I'm pretty much on the fence.

To me it sounds as if marking paths "C:foo" non-absolute and modify
resolveFile to deal with them the way you proposed normalizePath to do
would be the better approach.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Steve Loughran <st...@apache.org>.
Martijn Kruithof wrote:
> Matt Benson wrote:
> 
>> FileUtils.resolveFile claims to return absolute files;
>> however calling FileUtils.resolveFile(null, "\\") on
>> DOS returns the non-absolute File "\\".  So we lie. :)
>>
>> -Matt
>>  
>>
> 
> No file on windows is allowed to have \ in the name, so \\ would not be a
> valid file on dos at all (so not a non-absolute one, but none at all).
> 

FYI the DOS forbidden list is

\/:*?"<>|


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Matt Benson <gu...@yahoo.com>.
--- Martijn Kruithof <jm...@kruithof.xs4all.nl> wrote:

> Matt Benson wrote:
> 
> >FileUtils.resolveFile claims to return absolute
> files;
> >however calling FileUtils.resolveFile(null, "\\")
> on
> >DOS returns the non-absolute File "\\".  So we lie.
> 
> >:)
> >
> >-Matt
> >  
> >
> 
> No file on windows is allowed to have \ in the name,
> so \\ would not be a
> valid file on dos at all (so not a non-absolute one,
> but none at all).

Well, not in the name, but \ by itself ("\\" in Java)
is a relative filename meaning "root of the current
working drive."  As for \\ aka "\\\\" my opinion is
that is no file at all.  \ falls into the category of,
to be precise, relative files.  It may be easiest for
us to throw errors on this filename on DOS.  Likewise
for X:somefile with no separator after the colon;
currently we return a totally different File, which I
think crosses the line of acceptability.

-Matt


> 
> Martijn
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Martijn Kruithof <jm...@kruithof.xs4all.nl>.
Matt Benson wrote:

>FileUtils.resolveFile claims to return absolute files;
>however calling FileUtils.resolveFile(null, "\\") on
>DOS returns the non-absolute File "\\".  So we lie. 
>:)
>
>-Matt
>  
>

No file on windows is allowed to have \ in the name, so \\ would not be a
valid file on dos at all (so not a non-absolute one, but none at all).

Martijn

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Matt Benson <gu...@yahoo.com>.
--- Stefan Bodewig <bo...@apache.org> wrote:

> On Fri, 18 Feb 2005, Matt Benson
> <gu...@yahoo.com> wrote:
> 
> > So we lie.  :)
> 
> Please fix the docs 8-)

In this case, I'd rather fix the implementation.

-Matt
> 
> Stefan
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 18 Feb 2005, Matt Benson <gu...@yahoo.com> wrote:

> So we lie.  :)

Please fix the docs 8-)

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: FileUtils.normalize

Posted by Matt Benson <gu...@yahoo.com>.
Further file-related observations:

Project.resolveFile() methods claim to return
canonical files, but they actually defer to FileUtils
methods that claim to return absolute files.

FileUtils.resolveFile claims to return absolute files;
however calling FileUtils.resolveFile(null, "\\") on
DOS returns the non-absolute File "\\".  So we lie. 
:)

-Matt


--- Matt Benson <gu...@yahoo.com> wrote:

> This method will:
> 
>     * Uppercase the drive letter if there is one.
>     * Remove redundant slashes after the drive spec.
>     * Resolve all ./, .\, ../ and ..\ sequences.
>     * DOS style paths that start with a drive letter
> will have \ as the separator.
> 
> Other DOS considerations:
> 
> when a drive letter is supplied and there is no
> separator immediately following, the meaning is
> different.  Supplying the separator here yields the
> wrong filename.  In this case the meaning is that
> the
> remaining filename beyond the colon is relative to
> the
> current directory for that drive.  As we resolve .
> and
> .. components of the filename, I think we should be
> resolving this to the full path intended.
> 
> when a single separator leads the path, the path is
> relative to the root of the current directory.  I
> think we should be resolving that directory as well
> to
> be pointing to the correct file.
> 
> OR it may be that we should detect these conditions
> as
> NOT being absolute pathnames on DOS. 
> File.isAbsolute() returns false in these cases. 
> However, we should still provide some means of
> obtaining the absolute forms of these names as well.
> 
> The only reason I bring it up rather than just
> making
> the necessary changes is (1) that there is a choice
> of
> which to do, and (2) that the first alternative will
> break existing testcases (Project.testResolveFile at
> least).  No idea what the second (possibly more
> correct) alternative will break.
> 
> Thoughts?
> 
> -Matt
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> The all-new My Yahoo! - What will yours do?
> http://my.yahoo.com 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org