Esempio n. 1
0
/****************************************************************************
Desc: Creates a new 64-bit "file"
****************************************************************************/
RCODE F_MultiFileHdl::createFile(
	const char *	pszPath)
{
	RCODE					rc = NE_FLM_OK;
	FLMBOOL				bCreatedDir = FALSE;
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	if( m_bOpen)
	{
		rc = RC_SET_AND_ASSERT( NE_FLM_FAILURE);
		goto Exit;
	}

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

	f_strcpy( m_szPath, pszPath);
	bCreatedDir = TRUE;

	// Create the lock file

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

	// Initialize the EOF to 0 and set the state to open

	m_ui64EOF = 0;
	m_bOpen = TRUE;

Exit:

	// Release the lock file

	if( RC_BAD( rc))
	{
		(void)releaseLockFile( m_szPath, TRUE);
		if( bCreatedDir)
		{
			(void)pFileSystem->removeDir( m_szPath);
		}
	}

	return( rc);
}
Esempio n. 2
0
/****************************************************************************
Desc:	Creates a new 64-bit file with a unique, generated name
****************************************************************************/
RCODE F_MultiFileHdl::createUniqueFile(
	const char *		pszPath,					// Directory where the file is to be created
	const char *		pszFileExtension)		// Extension to be used on the new file.
{
	RCODE					rc = NE_FLM_OK;
	FLMUINT				uiCount;
	FLMBOOL				bModext = TRUE;
	FLMBOOL				bCreatedDir = FALSE;
	FLMUINT				uiBaseTime = 0;
	FLMBYTE				ucHighByte = 0;
	char					szDirName[ F_FILENAME_SIZE];
	char					szTmpPath[ F_PATH_MAX_SIZE];
	char					szBasePath[ F_PATH_MAX_SIZE];
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	if( m_bOpen)
	{
		rc = RC_SET_AND_ASSERT( NE_FLM_FAILURE);
		goto Exit;
	}

	if( !pszPath || pszPath[ 0] == '\0')
	{
#if defined( FLM_UNIX)
		f_strcpy( szBasePath, "./");
#elif defined( FLM_NLM)
		f_strcpy( szBasePath, "SYS:_NETWARE");
#else
		szBasePath[ 0] = '\0';
#endif
	}
	else
	{
		f_strcpy( szBasePath, pszPath);
	}

	if ((pszFileExtension) && (f_strlen( pszFileExtension) >= 3))
	{
		bModext = FALSE;
	}

	uiCount = 0;
	szDirName[ 0] = '\0';
	do
	{
		pFileSystem->pathCreateUniqueName( &uiBaseTime, szDirName, 
				pszFileExtension, &ucHighByte, bModext);

		f_strcpy( szTmpPath, szBasePath);
		pFileSystem->pathAppend( szTmpPath, szDirName);
		rc = pFileSystem->createDir( szTmpPath);
	} while ((rc != NE_FLM_OK) && (uiCount++ < 20));

	if( RC_BAD( rc))
	{
		goto Exit;
	}

	f_strcpy( m_szPath, szTmpPath);
	bCreatedDir = TRUE;

	// Create the lock file

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

	// Initialize the EOF to 0 and set the state to open

	m_ui64EOF = 0;
	m_bOpen = TRUE;

Exit:

	// Release the lock file

	if( RC_BAD( rc))
	{
		releaseLockFile( m_szPath, TRUE);

		if( bCreatedDir)
		{
			(void)pFileSystem->removeDir( m_szPath);
		}
	}

	return( rc);
}
Esempio n. 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);
}
Esempio n. 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);
	}
}