You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Felix Knecht <fe...@otego.com> on 2011/10/01 16:32:21 UTC
Uncheck file operations
Hi
ApacheDs and probably also Shared has in many locations file operations
like File.[delete|mkdir|...] where the return value (true|false) is
unchecked. In Java-1.7 exists static methods for this in
java.nio.file.Files [1] where an IOException is thrown if the operation
fails, in < Java-1.7 a SecurityException is thrown only in some special
cases and in all other cases the return value is 'false' and no
Exception is thrown [2]. IMO we should check the return value of these
operations and throw an IOException if the file/directory couldn't be
created/delete/renamed ...
If wanted I'll create a JIRA and go for it.
WDOT?
Regards
Felix
[1]
http://download.oracle.com/javase/7/docs/api/java/nio/file/Files.html#delete%28java.nio.file.Path%29
[2]
http://download.oracle.com/javase/6/docs/api/java/io/File.html#delete%28%29
Re: Uncheck file operations
Posted by Emmanuel Lecharny <el...@gmail.com>.
On 10/1/11 7:07 PM, Felix Knecht wrote:
> On 10/01/2011 06:49 PM, Emmanuel Lecharny wrote:
>> Yes. We may also consider commons-file, there might be some convenient
>> methods there.
>
> Your talking about commons-io forceDelete, forceMkdir?
> I'm not sure if also some renameTo or createFile do exist. Would you
> preferre in this case a mix of commons-io methods and -for not
> existing ones in commons-io - if (!File ...) or use all of the same?
I was thinking about methods like deleteQuietly which swallow the
Exception if any, and returns false if the file wasn't deleted.
But here, it's all about eating our own dog food.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com
Re: Uncheck file operations
Posted by Felix Knecht <fe...@apache.org>.
On 10/01/2011 06:49 PM, Emmanuel Lecharny wrote:
> Yes. We may also consider commons-file, there might be some convenient
> methods there.
Your talking about commons-io forceDelete, forceMkdir?
I'm not sure if also some renameTo or createFile do exist. Would you
preferre in this case a mix of commons-io methods and -for not existing
ones in commons-io - if (!File ...) or use all of the same?
http://commons.apache.org/io/api-release/org/apache/commons/io/FileUtils.html#forceDelete%28java.io.File%29
http://commons.apache.org/io/api-release/org/apache/commons/io/FileUtils.html#forceMkdir%28java.io.File%29
> Le 1 oct. 2011 18:42, "Felix Knecht"<fe...@apache.org> a écrit :
>>
>> On 10/01/2011 06:32 PM, Emmanuel Lecharny wrote:
>>>
>>> On 10/1/11 4:32 PM, Felix Knecht wrote:
>>>>
>>>> Hi
>>>>
>>>> ApacheDs and probably also Shared has in many locations file
>>>> operations like File.[delete|mkdir|...] where the return value
>>>> (true|false) is unchecked. In Java-1.7 exists static methods for this
>>>> in java.nio.file.Files [1] where an IOException is thrown if the
>>>> operation fails, in< Java-1.7 a SecurityException is thrown only in
>>>> some special cases and in all other cases the return value is 'false'
>>>> and no Exception is thrown [2]. IMO we should check the return value
>>>> of these operations and throw an IOException if the file/directory
>>>> couldn't be created/delete/renamed ...
>>>> If wanted I'll create a JIRA and go for it.
>>>
>>> Go for it, but keep in mind we still have to support Java 6...
>>
>>
>> I thought about some like which should be Java 6 compatible:
>>
>> if (!File.delete()) {
>> throw new IOException("Could not delete file ...");
>> }
>>
>>
>>>
>>> Thanks !
>>>
>>>
>>
>
Re: Uncheck file operations
Posted by Emmanuel Lecharny <el...@apache.org>.
Yes. We may also consider commons-file, there might be some convenient
methods there.
Le 1 oct. 2011 18:42, "Felix Knecht" <fe...@apache.org> a écrit :
>
> On 10/01/2011 06:32 PM, Emmanuel Lecharny wrote:
>>
>> On 10/1/11 4:32 PM, Felix Knecht wrote:
>>>
>>> Hi
>>>
>>> ApacheDs and probably also Shared has in many locations file
>>> operations like File.[delete|mkdir|...] where the return value
>>> (true|false) is unchecked. In Java-1.7 exists static methods for this
>>> in java.nio.file.Files [1] where an IOException is thrown if the
>>> operation fails, in < Java-1.7 a SecurityException is thrown only in
>>> some special cases and in all other cases the return value is 'false'
>>> and no Exception is thrown [2]. IMO we should check the return value
>>> of these operations and throw an IOException if the file/directory
>>> couldn't be created/delete/renamed ...
>>> If wanted I'll create a JIRA and go for it.
>>
>> Go for it, but keep in mind we still have to support Java 6...
>
>
> I thought about some like which should be Java 6 compatible:
>
> if (!File.delete()) {
> throw new IOException("Could not delete file ...");
> }
>
>
>>
>> Thanks !
>>
>>
>
Re: Uncheck file operations
Posted by Felix Knecht <fe...@apache.org>.
On 10/01/2011 06:32 PM, Emmanuel Lecharny wrote:
> On 10/1/11 4:32 PM, Felix Knecht wrote:
>> Hi
>>
>> ApacheDs and probably also Shared has in many locations file
>> operations like File.[delete|mkdir|...] where the return value
>> (true|false) is unchecked. In Java-1.7 exists static methods for this
>> in java.nio.file.Files [1] where an IOException is thrown if the
>> operation fails, in < Java-1.7 a SecurityException is thrown only in
>> some special cases and in all other cases the return value is 'false'
>> and no Exception is thrown [2]. IMO we should check the return value
>> of these operations and throw an IOException if the file/directory
>> couldn't be created/delete/renamed ...
>> If wanted I'll create a JIRA and go for it.
> Go for it, but keep in mind we still have to support Java 6...
I thought about some like which should be Java 6 compatible:
if (!File.delete()) {
throw new IOException("Could not delete file ...");
}
>
> Thanks !
>
>
Re: Uncheck file operations
Posted by Emmanuel Lecharny <el...@gmail.com>.
On 10/1/11 4:32 PM, Felix Knecht wrote:
> Hi
>
> ApacheDs and probably also Shared has in many locations file
> operations like File.[delete|mkdir|...] where the return value
> (true|false) is unchecked. In Java-1.7 exists static methods for this
> in java.nio.file.Files [1] where an IOException is thrown if the
> operation fails, in < Java-1.7 a SecurityException is thrown only in
> some special cases and in all other cases the return value is 'false'
> and no Exception is thrown [2]. IMO we should check the return value
> of these operations and throw an IOException if the file/directory
> couldn't be created/delete/renamed ...
> If wanted I'll create a JIRA and go for it.
Go for it, but keep in mind we still have to support Java 6...
Thanks !
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com