From f6b15061c86a1ff8faf94fb5f4d3b4dccd8c6646 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 25 Mar 2002 05:02:12 +0000 Subject: [PATCH] Abstracted file deletion, so we don't rely on C library for it anymore. --- archivers/dir.c | 8 +------- physfs.h | 7 +++++++ physfs_internal.h | 14 ++++++++++++++ platform/unix.c | 15 +++++++++++---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/archivers/dir.c b/archivers/dir.c index 9547f28d..69dd7752 100644 --- a/archivers/dir.c +++ b/archivers/dir.c @@ -299,13 +299,7 @@ static int DIR_remove(DirHandle *h, const char *name) int retval; BAIL_IF_MACRO(f == NULL, NULL, 0); - - /* !!! FIXME: Abstract in platform drivers. */ - errno = 0; - retval = (remove(f) == 0); - if (!retval) - __PHYSFS_setError(strerror(errno)); - + retval = __PHYSFS_platformDelete(f); free(f); return(retval); } /* DIR_remove */ diff --git a/physfs.h b/physfs.h index 025831ef..e59bfb31 100644 --- a/physfs.h +++ b/physfs.h @@ -596,6 +596,9 @@ __EXPORT__ int PHYSFS_mkdir(const char *dirName); * * A directory must be empty before this call can delete it. * + * Deleting a symlink will remove the link, not what it points to, regardless + * of whether you "permitSymLinks" or not. + * * So if you've got the write dir set to "C:\mygame\writedir" and call * PHYSFS_delete("downloads/maps/level1.map") then the file * "C:\mygame\writedir\downloads\maps\level1.map" is removed from the @@ -606,6 +609,10 @@ __EXPORT__ int PHYSFS_mkdir(const char *dirName); * actual file won't be removed until all processes that have an open * filehandle to it (including your program) close their handles. * + * Chances are, the bits that make up the file still exist, they are just + * made available to be written over at a later point. Don't consider this + * a security method or anything. :) + * * @param filename Filename to delete. * @return nonzero on success, zero on error. Specifics of the error can be * gleaned from PHYSFS_getLastError(). diff --git a/physfs_internal.h b/physfs_internal.h index 1b858150..335e5af9 100644 --- a/physfs_internal.h +++ b/physfs_internal.h @@ -619,6 +619,20 @@ char *__PHYSFS_platformRealPath(const char *path); */ int __PHYSFS_platformMkDir(const char *path); +/* + * Remove a file or directory entry in the actual filesystem. (path) is + * specified in platform-dependent notation. Note that this deletes files + * _and_ directories, so you might need to do some determination. + * Non-empty directories should report an error and not delete themselves + * or their contents. + * + * Deleting a symlink should remove the link, not what it points to. + * + * On error, return zero and set the error message. Return non-zero on success. + */ +int __PHYSFS_platformDelete(const char *path); + + #ifdef __cplusplus } #endif diff --git a/platform/unix.c b/platform/unix.c index ea5b72e1..3980b1dd 100644 --- a/platform/unix.c +++ b/platform/unix.c @@ -639,19 +639,26 @@ int __PHYSFS_platformEOF(void *opaque) int __PHYSFS_platformFlush(void *opaque) { - int rc = fflush((FILE *) opaque); - BAIL_IF_MACRO(rc == EOF, strerror(errno), 0); + errno = 0; + BAIL_IF_MACRO(fflush((FILE *) opaque) == EOF, strerror(errno), 0); return(1); } /* __PHYSFS_platformFlush */ int __PHYSFS_platformClose(void *opaque) { - int rc = fclose((FILE *) opaque); - BAIL_IF_MACRO(rc == EOF, strerror(errno), 0); + errno = 0; + BAIL_IF_MACRO(fclose((FILE *) opaque) == EOF, strerror(errno), 0); return(1); } /* __PHYSFS_platformClose */ +int __PHYSFS_platformDelete(const char *path) +{ + errno = 0; + BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0); + return(1); +} /* __PHYSFS_platformDelete */ + /* end of unix.c ... */