You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Great library - thanks for creating and maintaining it. I used this a couple of months ago and ran into what I think is a bug. The test case is below but basically if you move a file then it's unique name is not freed from its original parent directory, so you can't add a new file of the same name or move the old file back.
I fixed this in FatLfnDirectory.java by moving the call to "freeUniqueName()" from the remove() method (line 380) to the bottom of the the unlinkEntry() (now line 412).
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import de.waldheinz.fs.fat.FatFileSystem;
import de.waldheinz.fs.fat.FatLfnDirectory;
import de.waldheinz.fs.fat.FatLfnDirectoryEntry;
import de.waldheinz.fs.fat.SuperFloppyFormatter;
import de.waldheinz.fs.util.RamDisk;
public class MoveToReplaceTest {
private static final String FILE_NAME = "file";
private static final String DIRECTORY_NAME = "dir";
private FatLfnDirectoryEntry file;
private FatLfnDirectoryEntry dir;
private FatLfnDirectory root;
private FatFileSystem fs;
@Before
public void setUp() throws IOException {
RamDisk dev = new RamDisk(1024 * 1024);
fs = SuperFloppyFormatter.get(dev).format();
root = fs.getRoot();
file = root.addFile(FILE_NAME);
dir = root.addDirectory(DIRECTORY_NAME);
}
@Test
public void moveToAndReplaceTest() throws IOException {
// Move file form root to dir
file.moveTo(dir.getDirectory(), DIRECTORY_NAME);
// Check that the file has been moved and isn't in the original dir
assertEquals(file.getParent(), dir.getDirectory());
assertNull( root.getEntry(FILE_NAME) );
// Create a new file with a SAME filename in the original dir
try {
root.addFile(FILE_NAME);
} catch (IOException e) {
// Code will fail here
// java.io.IOException: an entry named file already exists
// at de.waldheinz.fs.fat.FatLfnDirectory.checkUniqueName(FatLfnDirectory.java:162)
// at de.waldheinz.fs.fat.FatLfnDirectory.addFile(FatLfnDirectory.java:135)
e.printStackTrace();
fail("IO Exception");
}
}
}
The text was updated successfully, but these errors were encountered:
Great library - thanks for creating and maintaining it. I used this a couple of months ago and ran into what I think is a bug. The test case is below but basically if you move a file then it's unique name is not freed from its original parent directory, so you can't add a new file of the same name or move the old file back.
I fixed this in FatLfnDirectory.java by moving the call to "freeUniqueName()" from the remove() method (line 380) to the bottom of the the unlinkEntry() (now line 412).
The text was updated successfully, but these errors were encountered: