summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2013-11-19 11:10:24 +0100
committerIngo Huerner <ingo.huerner@xse.de>2013-11-19 11:10:24 +0100
commitf6da03a5d34e943c48f75ef6fa18aced8a5cdd17 (patch)
tree9c61bb83b89dcb494a0460c64b4d6725ab87e9cd
parent90d08dc2cbc293ca15bec3d3ba7d96eac527c06b (diff)
downloadpersistence-client-library-f6da03a5d34e943c48f75ef6fa18aced8a5cdd17.tar.gz
Fixed a problem with the file interface, file handle was always 0
-rw-r--r--src/persistence_client_library_backup_filelist.c7
-rw-r--r--src/persistence_client_library_backup_filelist.h2
-rw-r--r--src/persistence_client_library_file.c22
-rw-r--r--test/persistence_client_library_test.c48
4 files changed, 60 insertions, 19 deletions
diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c
index 727e4e5..d6c58f7 100644
--- a/src/persistence_client_library_backup_filelist.c
+++ b/src/persistence_client_library_backup_filelist.c
@@ -220,13 +220,6 @@ int readBlacklistConfigFile(const char* filename)
-int need_backup_path(const char* path)
-{
- return need_backup_key(crc32(0, (const unsigned char*)path, strlen(path)));
-}
-
-
-
int need_backup_key(unsigned int key)
{
int rval = 1;
diff --git a/src/persistence_client_library_backup_filelist.h b/src/persistence_client_library_backup_filelist.h
index 091a0fc..d89181d 100644
--- a/src/persistence_client_library_backup_filelist.h
+++ b/src/persistence_client_library_backup_filelist.h
@@ -33,6 +33,4 @@ int readBlacklistConfigFile(const char* filename);
int need_backup_key(unsigned int key);
-int need_backup_path(const char* path);
-
#endif /* PERS_BACKUP_BLACKLIST_H */
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 3fab548..8047c34 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -170,7 +170,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc");
- if(pclVerifyConsistency(dbPath, backupPath, csumPath, flags) == -1)
+ if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1)
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!"));
return -1;
@@ -178,7 +178,11 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
}
// open file
- handle = open(dbPath, flags);
+ if(handle <= 0) // check if open is needed or already done in verifyConsistency
+ {
+ handle = open(dbPath, flags);
+ }
+
if(handle != -1)
{
@@ -423,11 +427,14 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc");
- if((pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1)
+ if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1)
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!"));
return -1;
}
+ // we don't need the file handle here
+ // the application calling this function must use the POSIX open() function to get an file descriptor
+ close(handle);
}
handle = get_persistence_handle_idx();
@@ -765,15 +772,12 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
remove(backupPath);
remove(csumPath);
}
- else
- {
- close(handle);
- }
return handle;
}
+
int pclRecoverFromBackup(int backupFd, const char* original)
{
int handle = 0;
@@ -798,6 +802,8 @@ int pclRecoverFromBackup(int backupFd, const char* original)
return handle;
}
+
+
int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const char* csumBuf)
{
int dstFd = 0, csfd = 0;
@@ -903,7 +909,7 @@ int pclCalcCrc32Csum(int fd, char crc32sum[])
int pclBackupNeeded(const char* path)
{
- return need_backup_path(path);
+ return need_backup_key(crc32(0, (const unsigned char*)path, strlen(path)));
}
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 358c431..6fc5992 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -634,8 +634,10 @@ END_TEST
*/
START_TEST(test_DataHandle)
{
- int handle1 = 0, handle2 = 0;
+ int handle1 = 0, handle2 = 0, size = 0;
+ int handleArray[4] = {0};
int ret = 0;
+ unsigned char buffer[READ_SIZE] = {0};
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
@@ -651,11 +653,53 @@ START_TEST(test_DataHandle)
ret = pclFileClose(1024);
fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
-
ret = pclFileClose(17);
fail_unless(ret == -1, "Could close file, but should not!!");
+ // test multiple handles
+ handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
+
+ handleArray[1] = pclFileOpen(0xFF, "media/mediaDB_write_02.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
+
+ handleArray[2] = pclFileOpen(0xFF, "media/mediaDB_write_03.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
+
+ handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
+
+ size = pclFileReadData(handleArray[0], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_01.db");
+
+ size = pclFileReadData(handleArray[1], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_02.db");
+
+ size = pclFileReadData(handleArray[2], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_03.db");
+
+ size = pclFileReadData(handleArray[3], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_04.db");
+
+ ret = pclKeyHandleClose(handleArray[0]);
+ fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
+
+ ret = pclKeyHandleClose(handleArray[1]);
+ fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
+
+ ret = pclKeyHandleClose(handleArray[2]);
+ fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
+ ret = pclKeyHandleClose(handleArray[3]);
+ fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
// test key handles
handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);