Exemple #1
0
	FINLINE void releaseLockFile(
		const char *		pszBasePath,
		FLMBOOL				bDelete)
	{
#ifndef FLM_UNIX
		F_UNREFERENCED_PARM( bDelete);
		F_UNREFERENCED_PARM( pszBasePath);
#endif

		if( m_pLockFileHdl)
		{

			// Release the lock file

			(void)m_pLockFileHdl->closeFile();
			m_pLockFileHdl->Release();
			m_pLockFileHdl = NULL;

#ifdef FLM_UNIX
			if( bDelete)
			{
				IF_FileSystem *	pFileSystem = f_getFileSysPtr();
				char					szTmpPath[ F_PATH_MAX_SIZE];

				// Delete the lock file

				f_strcpy( szTmpPath, pszBasePath);
				pFileSystem->pathAppend( szTmpPath, "64.LCK");
				pFileSystem->deleteFile( szTmpPath);
			}
#endif
		}
	}
Exemple #2
0
/****************************************************************************
Desc: This routine obtains exclusive access to a 64-bit file by creating
		a .lck file.  The object holds the .lck file open as long as the
		64-bit file is open.
****************************************************************************/
RCODE F_MultiFileHdl::createLockFile(
	const char *		pszBasePath)
{
	RCODE					rc = NE_FLM_OK;
	char					szLockPath [F_PATH_MAX_SIZE];
	F_FileHdl *			pLockFileHdl = NULL;
	FLMUINT				uiIoFlags = FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_SH_DENYRW;
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	f_strcpy( szLockPath, pszBasePath);
	pFileSystem->pathAppend( szLockPath, "64.LCK");

	// Attempt to create the lock file.  If it fails, the lock file
	// may have been left because of a crash.  Hence, we first try
	// to delete the file.  If that succeeds, we then attempt to
	// create the file again.  If it, or the 2nd create fail, we simply
	// return an access denied error.
	
	if( RC_BAD( rc = f_allocFileHdl( &pLockFileHdl)))
	{
		goto Exit;
	}

#ifndef FLM_UNIX
	// On Unix, we do not want to delete the file because it
	// will succeed even if someone else has the file open.
	
	uiIoFlags |= FLM_IO_DELETE_ON_RELEASE;
#endif

	if( RC_BAD( pLockFileHdl->createFile( szLockPath, uiIoFlags)))
	{
#ifndef FLM_UNIX
		if (RC_BAD( pFileSystem->deleteFile( szLockPath)))
		{
			rc = RC_SET( NE_FLM_IO_ACCESS_DENIED);
			goto Exit;
		}
		else if (RC_BAD( pLockFileHdl->createFile( szLockPath, uiIoFlags)))
		{
			rc = RC_SET( NE_FLM_IO_ACCESS_DENIED);
			goto Exit;
		}
#else

		if( RC_BAD( pLockFileHdl->openFile( szLockPath, uiIoFlags)))
		{
			rc = RC_SET( NE_FLM_IO_ACCESS_DENIED);
			goto Exit;
		}
#endif
	}

#ifdef FLM_UNIX
	if( RC_BAD( pLockFileHdl->lock()))
	{
		rc = RC_SET( NE_FLM_IO_ACCESS_DENIED);
		goto Exit;
	}
#endif

	m_pLockFileHdl = pLockFileHdl;
	pLockFileHdl = NULL;

Exit:

	if (pLockFileHdl)
	{
		(void)pLockFileHdl->closeFile();
		pLockFileHdl->Release();
		pLockFileHdl = NULL;
	}
	return( rc);
}
Exemple #3
0
/****************************************************************************
Desc:	Removes a 64-bit file
****************************************************************************/
RCODE F_MultiFileHdl::deleteMultiFile(
	const char *	pszPath)
{
	RCODE					rc = NE_FLM_OK;
	IF_DirHdl *			pDir = NULL;
	char					szTmpPath[ F_PATH_MAX_SIZE];
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	// Can't use this handle to delete something if we already
	// have a file open.

	if( m_bOpen)
	{

		// Can't jump to exit, because it calls releaseLockFile

		return( RC_SET_AND_ASSERT( NE_FLM_FAILURE));
	}

	if( RC_BAD( rc = pFileSystem->doesFileExist( pszPath)))
	{
		goto Exit;
	}

	if( !pFileSystem->isDir( pszPath))
	{
		// If the path specifies a single file rather than a
		// 64-bit directory, just go ahead and delete the file.

		rc = pFileSystem->deleteFile( pszPath);
		goto Exit;
	}

	if( RC_BAD( rc = createLockFile( pszPath)))
	{
		goto Exit;
	}

	if( RC_OK( pFileSystem->openDir( pszPath, "*.64", &pDir)))
	{
		// Remove all data files

		for( rc = pDir->next(); !RC_BAD( rc) ; rc = pDir->next())
		{
			pDir->currentItemPath( szTmpPath);
			f_assert( f_strstr( szTmpPath, ".64") != 0);
			(void)pFileSystem->deleteFile( szTmpPath);
		}

		pDir->Release();
		pDir = NULL;
		rc = NE_FLM_OK;
	}

	// Release and delete the lock file

	(void)releaseLockFile( pszPath, TRUE);

	// Remove the directory

	(void)pFileSystem->removeDir( pszPath);

Exit:

	(void)releaseLockFile( pszPath, FALSE);

	return( rc);
}
Exemple #4
0
/****************************************************************************
Desc:	Closes all data files associated with the object
****************************************************************************/
void F_MultiFileHdl::closeFile(
	FLMBOOL			bDelete)
{
	RCODE					rc = NE_FLM_OK;
	FLMUINT				uiLoop;
	IF_DirHdl *			pDir = NULL;
	char					szTmpPath[ F_PATH_MAX_SIZE];
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	if( !m_bOpen)
	{
		return;
	}

	for( uiLoop = 0; uiLoop < F_MULTI_FHDL_LIST_SIZE; uiLoop++)
	{
		if( m_pFileHdlList[ uiLoop].pFileHdl)
		{
			if( m_pFileHdlList[ uiLoop].bDirty)
			{
				(void)m_pFileHdlList[ uiLoop].pFileHdl->flush();
			}
			m_pFileHdlList[ uiLoop].pFileHdl->closeFile();
			m_pFileHdlList[ uiLoop].pFileHdl->Release();
			f_memset( &m_pFileHdlList[ uiLoop], 0, sizeof( FH_INFO));
		}
	}

	m_ui64EOF = 0;
	m_bOpen = FALSE;

	if( bDelete)
	{
		if( RC_OK( pFileSystem->openDir(
			m_szPath, "*.64", &pDir)))
		{
			// Remove all data files

			for( rc = pDir->next(); !RC_BAD( rc) ; rc = pDir->next())
			{
				pDir->currentItemPath( szTmpPath);
				f_assert( f_strstr( szTmpPath, ".64") != 0);
				(void)pFileSystem->deleteFile( szTmpPath);
			}

			pDir->Release();
			pDir = NULL;
		}

		// Release and delete the lock file

		(void)releaseLockFile( m_szPath, TRUE);

		// Remove the directory

		(void)pFileSystem->removeDir( m_szPath);
	}
	else
	{
		(void)releaseLockFile( m_szPath, FALSE);
	}
}