summaryrefslogtreecommitdiff
path: root/src/persistence_client_library_file.c
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 /src/persistence_client_library_file.c
parent90d08dc2cbc293ca15bec3d3ba7d96eac527c06b (diff)
downloadpersistence-client-library-f6da03a5d34e943c48f75ef6fa18aced8a5cdd17.tar.gz
Fixed a problem with the file interface, file handle was always 0
Diffstat (limited to 'src/persistence_client_library_file.c')
-rw-r--r--src/persistence_client_library_file.c22
1 files changed, 14 insertions, 8 deletions
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)));
}