base/fs/m_fs.c
/* Used by copy and move to determine if we can write to the given path
 * based on a file already existing there or not.
 *
 * access is used to determine existence because we don't want to overwrite
 * if there already is a file. This is not guaranteed because if there is
 * a race condition where a file is created after this check it will be
 * overwritten. Not much we can do about that. It shouldn't pose a security
 * issue since this is more of a request than a requirement.
 */
Used by copy and move to determine if we can write to the given path
based on a file already existing there or not.

access is used to determine existence because we don't want to overwrite
if there already is a file. This is not guaranteed because if there is
a race condition where a file is created after this check it will be
overwritten. Not much we can do about that. It shouldn't pose a security
issue since this is more of a request than a requirement.
Used by copy and move to determine if we can write to the given path based on a file already existing there or not . access is used to determine existence because we don ' t want to overwrite if there already is a file . This is not guaranteed because if there is a race condition where a file is created after this check it will be overwritten . Not much we can do about that . It shouldn ' t pose a security issue since this is more of a request than a requirement .
static M_bool M_fs_check_overwrite_allowed(const char *p1, const char *p2, M_uint32 mode)
{
	M_fs_info_t  *info = NULL;
	char         *pold = NULL;
	char         *pnew = NULL;
	M_fs_type_t   type;
	M_bool        ret  = M_TRUE;
	if (mode & M_FS_FILE_MODE_OVERWRITE)
		return M_TRUE;
	if (M_fs_info(&info, p1, M_FS_PATH_INFO_FLAGS_BASIC) != M_FS_ERROR_SUCCESS)
		return M_FALSE;
	type = M_fs_info_get_type(info);
	M_fs_info_destroy(info);
	if (type != M_FS_TYPE_DIR) {
		if (M_fs_perms_can_access(p2, M_FS_PERMS_MODE_NONE) == M_FS_ERROR_SUCCESS) {
			ret = M_FALSE;
			goto done;
		}
	}
	pold = M_fs_path_basename(p1, M_FS_SYSTEM_AUTO);
	pnew = M_fs_path_join(p2, pnew, M_FS_SYSTEM_AUTO);
	if (M_fs_perms_can_access(pnew, M_FS_PERMS_MODE_NONE) == M_FS_ERROR_SUCCESS) {
		ret = M_FALSE;
		goto done;
	}
done:
	M_free(pnew);
	M_free(pold);
	return ret;
}
static M_bool M_fs_check_overwrite_allowed ( const char * p1 , const char * p2 , M_uint32 mode ) { M_fs_info_t * info = NULL ; char * pold = NULL ; char * pnew = NULL ; M_fs_type_t type ; M_bool ret = M_TRUE ; if ( mode & M_FS_FILE_MODE_OVERWRITE ) return M_TRUE ; if ( M_fs_info ( & info , p1 , M_FS_PATH_INFO_FLAGS_BASIC ) != M_FS_ERROR_SUCCESS ) return M_FALSE ; type = M_fs_info_get_type ( info ) ; M_fs_info_destroy ( info ) ; if ( type != M_FS_TYPE_DIR ) { if ( M_fs_perms_can_access ( p2 , M_FS_PERMS_MODE_NONE ) == M_FS_ERROR_SUCCESS ) { ret = M_FALSE ; goto done ; } } pold = M_fs_path_basename ( p1 , M_FS_SYSTEM_AUTO ) ; pnew = M_fs_path_join ( p2 , pnew , M_FS_SYSTEM_AUTO ) ; if ( M_fs_perms_can_access ( pnew , M_FS_PERMS_MODE_NONE ) == M_FS_ERROR_SUCCESS ) { ret = M_FALSE ; goto done ; } done : M_free ( pnew ) ; M_free ( pold ) ; return ret ; }
Used by copy and move to determine if we can write to the given path
 based on a file already existing there or not.
Used by copy and move to determine if we can write to the given path based on a file already existing there or not .
/* If we're not overwriting we need to verify existance.
 	 *
 	 * For files we need to check if the file name exists in the
	 * directory it's being copied to.
	 *
	 * For directories we need to check if the directory name
	 * exists in the directory it's being copied to.
	 */ /* File exists at path. */ /* Is dir */