File.delete() potentially damages file systems.

Project:JNode FS
Component:Code
Category:bug report
Priority:critical
Assigned:Stephen Crawley
Status:active
Description

While fixing the problems in 'del' I accidentally made a change that caused it to try to delete a non-empty directory. Much my surprise it "worked"; i.e. the File.delete(file) call returned "true" and directory was gone, according to "dir". This deserved some investigation. (If it really worked, why would the DeleteCommand class need to go to the trouble of recursing over the subdir tree???)

It turns out that File.delete(new File("someDir")) does not check that the directory is empty. More specifically, the code in FileSystemAPIImpl calls parentDir.remove(...) without doing any checks, and the one FSDirectory type that I looked at (Ext2) didn't check either!

If my reading of the code is correct, calling File.delete(..) on a non-empty directory is going to turn the directory's contents into orphans .... at least for the Ext2 file system. This is bad, since file systems are not garbage collected. Not withstanding what DeleteCommand does, the File.delete(..) method must either refuse to delete non-empty directories (preferred IMO) or do a proper job of deleting them. And the behavior should be consistent across all file system types.

#1

Project:JNode Core» JNode FS

I changed this bug to allow comments. Moved to FS.

#2

Java's own behaviour is to return false if the directory has anything in it.

This is probably one of those things which should be fixed outside the FS drivers so that it works the same in all cases.

#3

Assigned to:Anonymous» Stephen Crawley