- fs_delete() will also delete helper files

This commit is contained in:
cebix 1999-11-08 17:00:14 +00:00
parent 5bad3ea92e
commit 30b45e559b
5 changed files with 70 additions and 10 deletions

View File

@ -365,6 +365,31 @@ size_t extfs_write(int fd, void *buffer, size_t length)
} }
/*
* Remove file/directory (and associated helper files),
* returns false on error (and sets errno)
*/
bool extfs_remove(const char *path)
{
// Remove helpers first, don't complain if this fails
char helper_path[MAX_PATH_LENGTH];
make_helper_path(path, helper_path, ".finf/", false);
remove(helper_path);
make_helper_path(path, helper_path, ".rsrc/", false);
remove(helper_path);
// Now remove file or directory
if (remove(path) < 0) {
if (errno == EISDIR)
return rmdir(path) == 0;
else
return false;
}
return true;
}
/* /*
* ftruncate() is missing from libnix * ftruncate() is missing from libnix
*/ */

View File

@ -455,3 +455,19 @@ size_t extfs_write(int fd, void *buffer, size_t length)
} }
return actual; return actual;
} }
/*
* Remove file/directory, returns false on error (and sets errno)
*/
bool extfs_remove(const char *path)
{
if (remove(path) < 0) {
if (errno == EISDIR)
return rmdir(path) == 0;
else
return false;
}
return true;
}

View File

@ -368,3 +368,28 @@ size_t extfs_write(int fd, void *buffer, size_t length)
errno = 0; errno = 0;
return write(fd, buffer, length); return write(fd, buffer, length);
} }
/*
* Remove file/directory (and associated helper files),
* returns false on error (and sets errno)
*/
bool extfs_remove(const char *path)
{
// Remove helpers first, don't complain if this fails
char helper_path[MAX_PATH_LENGTH];
make_helper_path(path, helper_path, ".finf/", false);
remove(helper_path);
make_helper_path(path, helper_path, ".rsrc/", false);
remove(helper_path);
// Now remove file or directory
if (remove(path) < 0) {
if (errno == EISDIR)
return rmdir(path) == 0;
else
return false;
}
return true;
}

View File

@ -1898,16 +1898,9 @@ static int16 fs_delete(uint32 pb, uint32 dirID)
return result; return result;
// Delete file // Delete file
if (remove(full_path) < 0) { if (!extfs_remove(full_path))
int16 err = errno2oserr(); return errno2oserr();
if (errno == EISDIR) { // Workaround for BeOS bug else
if (rmdir(full_path) < 0)
return errno2oserr();
else
return noErr;
} else
return err;
} else
return noErr; return noErr;
} }

View File

@ -42,6 +42,7 @@ extern int open_rfork(const char *path, int flag);
extern void close_rfork(const char *path, int fd); extern void close_rfork(const char *path, int fd);
extern size_t extfs_read(int fd, void *buffer, size_t length); extern size_t extfs_read(int fd, void *buffer, size_t length);
extern size_t extfs_write(int fd, void *buffer, size_t length); extern size_t extfs_write(int fd, void *buffer, size_t length);
extern bool extfs_remove(const char *path);
// Maximum length of full path name // Maximum length of full path name
const int MAX_PATH_LENGTH = 1024; const int MAX_PATH_LENGTH = 1024;