Skip to content

Commit

Permalink
Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSear…
Browse files Browse the repository at this point in the history
…chPath.
  • Loading branch information
icculus committed Aug 22, 2010
1 parent c306d73 commit c1969d0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions extras/physfs-swig.i
Expand Up @@ -88,6 +88,7 @@
%rename(stat) PHYSFS_stat;
%rename(readBytes) PHYSFS_readBytes;
%rename(writeBytes) PHYSFS_writeBytes;
%rename(unmount) PHYSFS_unmount;
#endif

%include "../src/physfs.h"
Expand Down
16 changes: 11 additions & 5 deletions src/physfs.c
Expand Up @@ -1003,6 +1003,12 @@ int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)


int PHYSFS_removeFromSearchPath(const char *oldDir)
{
return PHYSFS_unmount(oldDir);
} /* PHYSFS_removeFromSearchPath */


int PHYSFS_unmount(const char *oldDir)
{
DirHandle *i;
DirHandle *prev = NULL;
Expand Down Expand Up @@ -1030,7 +1036,7 @@ int PHYSFS_removeFromSearchPath(const char *oldDir)
} /* for */

BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0);
} /* PHYSFS_removeFromSearchPath */
} /* PHYSFS_unmount */


char **PHYSFS_getSearchPath(void)
Expand Down Expand Up @@ -1081,7 +1087,7 @@ static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep,
if (str != NULL)
{
sprintf(str, "%s%s%s", d, dirsep, i);
PHYSFS_addToSearchPath(str, archivesFirst == 0);
PHYSFS_mount(str, NULL, archivesFirst == 0);
__PHYSFS_smallFree(str);
} /* if */
} /* setSaneCfgAddPath */
Expand Down Expand Up @@ -1133,19 +1139,19 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName,
} /* if */

/* Put write dir first in search path... */
PHYSFS_addToSearchPath(str, 0);
PHYSFS_mount(str, NULL, 0);
__PHYSFS_smallFree(str);

/* Put base path on search path... */
PHYSFS_addToSearchPath(basedir, 1);
PHYSFS_mount(basedir, NULL, 1);

/* handle CD-ROMs... */
if (includeCdRoms)
{
char **cds = PHYSFS_getCdRomDirs();
char **i;
for (i = cds; *i != NULL; i++)
PHYSFS_addToSearchPath(*i, 1);
PHYSFS_mount(*i, NULL, 1);

PHYSFS_freeList(cds);
} /* if */
Expand Down
60 changes: 48 additions & 12 deletions src/physfs.h
Expand Up @@ -800,8 +800,14 @@ PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
* \fn int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
* \brief Add an archive or directory to the search path.
*
* This is a legacy call in PhysicsFS 2.0, equivalent to:
* PHYSFS_mount(newDir, NULL, appendToPath);
* \deprecated As of PhysicsFS 2.0, use PHYSFS_mount() instead. This
* function just wraps it anyhow.
*
* This function is equivalent to:
*
* \code
* PHYSFS_mount(newDir, NULL, appendToPath);
* \endcode
*
* You must use this and not PHYSFS_mount if binary compatibility with
* PhysicsFS 1.0 is important (which it may not be for many people).
Expand All @@ -810,27 +816,35 @@ PHYSFS_DECL int PHYSFS_setWriteDir(const char *newDir);
* \sa PHYSFS_removeFromSearchPath
* \sa PHYSFS_getSearchPath
*/
PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath);

PHYSFS_DECL int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
PHYSFS_DEPRECATED;

/**
* \fn int PHYSFS_removeFromSearchPath(const char *oldDir)
* \brief Remove a directory or archive from the search path.
*
* This must be a (case-sensitive) match to a dir or archive already in the
* search path, specified in platform-dependent notation.
* \deprecated As of PhysicsFS 2.1, use PHYSFS_unmount() instead. This
* function just wraps it anyhow. There's no functional difference
* except the vocabulary changed from "adding to the search path"
* to "mounting" when that functionality was extended, and thus
* the preferred way to accomplish this function's work is now
* called "unmounting."
*
* This call will fail (and fail to remove from the path) if the element still
* has files open in it.
* This function is equivalent to:
*
* \param oldDir dir/archive to remove.
* \return nonzero on success, zero on failure.
* Specifics of the error can be gleaned from PHYSFS_getLastError().
* \code
* PHYSFS_unmount(oldDir);
* \endcode
*
* You must use this and not PHYSFS_unmount if binary compatibility with
* PhysicsFS 1.0 is important (which it may not be for many people).
*
* \sa PHYSFS_addToSearchPath
* \sa PHYSFS_getSearchPath
* \sa PHYSFS_unmount
*/
PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir);
PHYSFS_DECL int PHYSFS_removeFromSearchPath(const char *oldDir)
PHYSFS_DEPRECATED;


/**
Expand Down Expand Up @@ -2475,6 +2489,28 @@ PHYSFS_DECL void PHYSFS_utf8FromLatin1(const char *src, char *dst,

/* Everything above this line is part of the PhysicsFS 2.0 API. */

/**
* \fn int PHYSFS_unmount(const char *oldDir)
* \brief Remove a directory or archive from the search path.
*
* This is functionally equivalent to PHYSFS_removeFromSearchPath(), but that
* function is deprecated to keep the vocabulary paired with PHYSFS_mount().
*
* This must be a (case-sensitive) match to a dir or archive already in the
* search path, specified in platform-dependent notation.
*
* This call will fail (and fail to remove from the path) if the element still
* has files open in it.
*
* \param oldDir dir/archive to remove.
* \return nonzero on success, zero on failure.
* Specifics of the error can be gleaned from PHYSFS_getLastError().
*
* \sa PHYSFS_getSearchPath
* \sa PHYSFS_mount
*/
PHYSFS_DECL int PHYSFS_unmount(const char *oldDir);

/**
* \fn const PHYSFS_Allocator *PHYSFS_getAllocator(void)
* \brief Discover the current allocator.
Expand Down
5 changes: 3 additions & 2 deletions test/test_physfs.c
Expand Up @@ -119,7 +119,7 @@ static int cmd_addarchive(char *args)

/*printf("[%s], [%d]\n", args, appending);*/

if (PHYSFS_addToSearchPath(args, appending))
if (PHYSFS_mount(args, NULL, appending))
printf("Successful.\n");
else
printf("Failure. reason: %s.\n", PHYSFS_getLastError());
Expand Down Expand Up @@ -189,7 +189,7 @@ static int cmd_removearchive(char *args)
args[strlen(args) - 1] = '\0';
} /* if */

if (PHYSFS_removeFromSearchPath(args))
if (PHYSFS_unmount(args))
printf("Successful.\n");
else
printf("Failure. reason: %s.\n", PHYSFS_getLastError());
Expand Down Expand Up @@ -1024,6 +1024,7 @@ static const command_info commands[] =
{ "addarchive", cmd_addarchive, 2, "<archiveLocation> <append>" },
{ "mount", cmd_mount, 3, "<archiveLocation> <mntpoint> <append>" },
{ "removearchive", cmd_removearchive, 1, "<archiveLocation>" },
{ "unmount", cmd_removearchive, 1, "<archiveLocation>" },
{ "enumerate", cmd_enumerate, 1, "<dirToEnumerate>" },
{ "ls", cmd_enumerate, 1, "<dirToEnumerate>" },
{ "getlasterror", cmd_getlasterror, 0, NULL },
Expand Down

0 comments on commit c1969d0

Please sign in to comment.