summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Begumisa <ben_g@users.sourceforge.net>2007-09-04 19:56:54 +0000
committerGerald Begumisa <ben_g@users.sourceforge.net>2007-09-04 19:56:54 +0000
commit13d24d7f97fe6e739c47388279c63b961a7b8bc3 (patch)
treefe88e699741858ae0459d5b43e1c7b2422cd7dc0
parent01240e01f8e4e63cbbdfebfb8b566e61e454cc7a (diff)
Ownership and permissions for MCF files now set at creation time, ownership and permissions code moved to Utils.cpp/h
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@479 09dcff7a-b715-0410-9601-b79a96267cd0
-rw-r--r--orkbasecxx/BatchProcessing.cpp64
-rw-r--r--orkbasecxx/Utils.cpp54
-rw-r--r--orkbasecxx/Utils.h2
-rw-r--r--orkbasecxx/audiofile/MediaChunkFile.cpp10
4 files changed, 70 insertions, 60 deletions
diff --git a/orkbasecxx/BatchProcessing.cpp b/orkbasecxx/BatchProcessing.cpp
index 62d4d2d..dd082b0 100644
--- a/orkbasecxx/BatchProcessing.cpp
+++ b/orkbasecxx/BatchProcessing.cpp
@@ -318,16 +318,11 @@ void BatchProcessing::ThreadHandler(void *args)
LOG4CXX_INFO(LOG.batchProcessingLog, logMsg);
CStdString audioFilePath = CONFIG.m_audioOutputPath + "/" + audioTapeRef->GetPath();
- CStdString audioFileName, mcfFileName;
+ CStdString audioFileName;
audioFileName = audioFilePath + "/" + audioTapeRef->GetIdentifier() + outFileRef->GetExtension();
- mcfFileName = audioFilePath + "/" + audioTapeRef->GetIdentifier() + fileRef->GetExtension();
-
- //LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " audioFileName: " + audioFileName + " mcfFileName: " + mcfFileName);
-
-#ifndef WIN32
if(CONFIG.m_audioFilePermissions) {
- if(chmod(audioFileName.c_str(), CONFIG.m_audioFilePermissions))
+ if(FileSetPermissions(audioFileName, CONFIG.m_audioFilePermissions))
{
CStdString logMsg;
@@ -336,65 +331,14 @@ void BatchProcessing::ThreadHandler(void *args)
}
}
- if(CONFIG.m_audioFilePermissions) {
- if(chmod(mcfFileName.c_str(), CONFIG.m_audioFilePermissions))
- {
- CStdString logMsg;
-
- logMsg.Format("Error setting permissions of %s to %o: %s", mcfFileName.c_str(), CONFIG.m_audioFilePermissions, strerror(errno));
- LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg);
- }
- }
-
if(CONFIG.m_audioFileGroup.size() && CONFIG.m_audioFileOwner.size()) {
- struct group fileGroup, *fgP = NULL;
- struct passwd fileUser, *fuP = NULL;
- char infoGroupBuf[4096], infoUserBuf[4096];
-
- memset(infoGroupBuf, 0, sizeof(infoGroupBuf));
- memset(infoUserBuf, 0, sizeof(infoUserBuf));
- memset(&fileGroup, 0, sizeof(fileGroup));
- memset(&fileUser, 0, sizeof(fileUser));
-
- if(!getgrnam_r(CONFIG.m_audioFileGroup.c_str(), &fileGroup, infoGroupBuf, sizeof(infoGroupBuf), &fgP))
- {
- if(!getpwnam_r(CONFIG.m_audioFileOwner.c_str(), &fileUser, infoUserBuf, sizeof(infoUserBuf), &fuP))
- {
-
- if(chown(audioFileName.c_str(), fileUser.pw_uid, fileGroup.gr_gid))
- {
- CStdString logMsg;
-
- logMsg.Format("Error setting ownership and group of %s to %s:%s: %s", audioFileName.c_str(), CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup, strerror(errno));
- LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg);
- }
-
- if(chown(mcfFileName.c_str(), fileUser.pw_uid, fileGroup.gr_gid))
- {
- CStdString logMsg;
-
- logMsg.Format("Error setting ownership and group of %s to %s:%s: %s", mcfFileName.c_str(), CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup, strerror(errno));
- LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg);
- }
- }
- else
- {
- CStdString logMsg;
-
- logMsg.Format("Failed to get user information for user %s, please check the AudioFileOwner parameter in config.xml", CONFIG.m_audioFileOwner);
- LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg);
- }
- }
- else
+ if(FileSetOwnership(audioFileName, CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup))
{
- CStdString logMsg;
-
- logMsg.Format("Failed to get group information for group %s, please check the AudioFileGroup parameter in config.xml", CONFIG.m_audioFileGroup);
+ logMsg.Format("Error setting ownership and group of %s to %s:%s: %s", audioFileName.c_str(), CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup, strerror(errno));
LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " " + logMsg);
}
}
-#endif
if(CONFIG.m_deleteNativeFile)
{
fileRef->Delete();
diff --git a/orkbasecxx/Utils.cpp b/orkbasecxx/Utils.cpp
index d1139ba..fa670e4 100644
--- a/orkbasecxx/Utils.cpp
+++ b/orkbasecxx/Utils.cpp
@@ -3,6 +3,11 @@
#include "ace/OS_NS_arpa_inet.h"
#include "ace/OS_NS_sys_stat.h"
+#ifndef WIN32
+#include <pwd.h>
+#include <grp.h>
+#endif
+
//========================================================
// file related stuff
@@ -85,6 +90,55 @@ void FileRecursiveMkdir(CStdString& path)
}
}
+int FileSetPermissions(CStdString filename, int permissions)
+{
+ int res = 0;
+
+#ifndef WIN32
+ res = chmod(filename.c_str(), permissions);
+#endif
+
+ return res;
+}
+
+int FileSetOwnership(CStdString filename, CStdString owner, CStdString group)
+{
+ int res = 0;
+
+#ifndef WIN32
+ struct group fileGroup, *fgP = NULL;
+ struct passwd fileUser, *fuP = NULL;
+ char infoGroupBuf[4096], infoUserBuf[4096];
+
+ memset(infoGroupBuf, 0, sizeof(infoGroupBuf));
+ memset(infoUserBuf, 0, sizeof(infoUserBuf));
+ memset(&fileGroup, 0, sizeof(fileGroup));
+ memset(&fileUser, 0, sizeof(fileUser));
+
+ if(!getgrnam_r(group.c_str(), &fileGroup, infoGroupBuf, sizeof(infoGroupBuf), &fgP))
+ {
+ if(!getpwnam_r(owner.c_str(), &fileUser, infoUserBuf, sizeof(infoUserBuf), &fuP))
+ {
+ if(chown(filename.c_str(), fileUser.pw_uid, fileGroup.gr_gid))
+ {
+ res = -1;
+ }
+ }
+ else
+ {
+ res = -1;
+ }
+ }
+ else
+ {
+ res = -1;
+ }
+#endif
+
+ return res;
+}
+
+
//=====================================================
// Network related stuff
diff --git a/orkbasecxx/Utils.h b/orkbasecxx/Utils.h
index f6d1762..dd82b76 100644
--- a/orkbasecxx/Utils.h
+++ b/orkbasecxx/Utils.h
@@ -74,6 +74,8 @@ CStdString DLL_IMPORT_EXPORT_ORKBASE FilePath(CStdString& path);
CStdString DLL_IMPORT_EXPORT_ORKBASE FileStripExtension(CStdString& filename);
bool DLL_IMPORT_EXPORT_ORKBASE FileCanOpen(CStdString& path);
void DLL_IMPORT_EXPORT_ORKBASE FileRecursiveMkdir(CStdString& path);
+int DLL_IMPORT_EXPORT_ORKBASE FileSetPermissions(CStdString filename, int permissions);
+int DLL_IMPORT_EXPORT_ORKBASE FileSetOwnership(CStdString filename, CStdString owner, CStdString group);
//=====================================================
diff --git a/orkbasecxx/audiofile/MediaChunkFile.cpp b/orkbasecxx/audiofile/MediaChunkFile.cpp
index aa89277..314f337 100644
--- a/orkbasecxx/audiofile/MediaChunkFile.cpp
+++ b/orkbasecxx/audiofile/MediaChunkFile.cpp
@@ -178,6 +178,16 @@ void MediaChunkFile::Open(CStdString& filename, fileOpenModeEnum mode, bool ster
{
FileRecursiveMkdir(m_filename);
m_stream = ACE_OS::fopen((PCSTR)m_filename, "wb");
+
+ if(CONFIG.m_audioFilePermissions)
+ {
+ FileSetPermissions(m_filename, CONFIG.m_audioFilePermissions);
+ }
+
+ if(CONFIG.m_audioFileGroup.size() && CONFIG.m_audioFileOwner.size())
+ {
+ FileSetOwnership(m_filename, CONFIG.m_audioFileOwner, CONFIG.m_audioFileGroup);
+ }
}
if(!m_stream)
{