Removal fully functioning
This commit is contained in:
parent
f80ff37587
commit
6a7068d22a
@ -87,7 +87,6 @@ void _ListFS_(FileSystem* fs, ino_t inodeNumber, short unsigned numtabs)
|
||||
}
|
||||
|
||||
// Remove a file from the filesystem
|
||||
// TODO: Fix function so that it adds directories, then the file after
|
||||
void RemoveFileFromFS(FileSystem* fs, char* fname)
|
||||
{
|
||||
_RemoveFileFromFS_(fs, 0, fname);
|
||||
@ -103,7 +102,12 @@ int _RemoveFileFromFS_(FileSystem* fs, ino_t inodeNumber, char* fname)
|
||||
if (!(fs->inodes[inodeNumber].blocks[i].isValid))
|
||||
continue;
|
||||
if (fs->inodes[inodeNumber].blocks[i].isDirectory)
|
||||
{
|
||||
emptyDir =_RemoveFileFromFS_(fs, fs->inodes[inodeNumber].blocks[i].inode, fname + FindNextDirectory(fname) + 1);
|
||||
if (emptyDir)
|
||||
fs->inodes[inodeNumber].blocks[i].isValid = 0;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(fs->inodes[inodeNumber].blocks[i].name, fname) == 0)
|
||||
fs->inodes[inodeNumber].blocks[i].isValid = 0;
|
||||
else
|
||||
@ -111,6 +115,7 @@ int _RemoveFileFromFS_(FileSystem* fs, ino_t inodeNumber, char* fname)
|
||||
}
|
||||
if (!emptyDir)
|
||||
return 0;
|
||||
fs->inodes[inodeNumber].isValid = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
20
test/test.c
20
test/test.c
@ -106,12 +106,24 @@ void Test_FileSystem_Should_ListContents(void)
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("test1.txt", fakefs->inodes[2].blocks[0].name, 9);
|
||||
TEST_MESSAGE("This only runs the list operation. Check info yourself.");
|
||||
}
|
||||
void Test_FileSystem_Should_RemoveFile(void)
|
||||
void Test_FileSystem_Should_RemoveFirstFile(void)
|
||||
{
|
||||
RunFuse(fakefs, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(0, fakefs->inodes[2].blocks[0].isValid);
|
||||
}
|
||||
|
||||
void Test_FileSystem_Should_RemoveSecondFile(void)
|
||||
{
|
||||
RunFuse(fakefs, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(0, fakefs->inodes[2].blocks[1].isValid);
|
||||
}
|
||||
|
||||
void Test_FileSystem_Should_RemoveThirdFile(void)
|
||||
{
|
||||
RunFuse(fakefs, &dummyFuse);
|
||||
TEST_ASSERT_EQUAL(0, fakefs->inodes[2].blocks[2].isValid);
|
||||
}
|
||||
|
||||
void Test_FileSystem_Should_RemoveEmptyDirectories(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, fakefs->inodes[2].isValid);
|
||||
@ -141,8 +153,12 @@ int main(void)
|
||||
argv[1] = "-l";
|
||||
RUN_TEST(Test_FileSystem_Should_ListContents);
|
||||
argv[1] = "-r";
|
||||
argv[2] = "test/files/test1.txt";
|
||||
RUN_TEST(Test_FileSystem_Should_RemoveFirstFile);
|
||||
argv[2] = "test/files/test2.txt";
|
||||
RUN_TEST(Test_FileSystem_Should_RemoveFile);
|
||||
RUN_TEST(Test_FileSystem_Should_RemoveSecondFile);
|
||||
argv[2] = "test/files/test3.txt";
|
||||
RUN_TEST(Test_FileSystem_Should_RemoveThirdFile);
|
||||
RUN_TEST(Test_FileSystem_Should_RemoveEmptyDirectories);
|
||||
return UNITY_END();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user