mirror of
https://github.com/znc/znc.git
synced 2026-05-02 11:32:29 +02:00
Move m_sHomePath from CZNC to CFile
Thanks to this change, linking the following object files produces no unresolved symbols: FileUtils.o Utils.o ZNCString.o MD5.o SHA256.o The idea here is that ZNC is a little better modularized. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "znc.h"
|
||||
#include "Utils.h"
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#ifndef HAVE_LSTAT
|
||||
# define lstat(a, b) stat(a, b)
|
||||
@@ -22,6 +22,8 @@
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
|
||||
CString CFile::m_sHomePath;
|
||||
|
||||
CFile::CFile() {
|
||||
m_iFD = -1;
|
||||
}
|
||||
@@ -38,7 +40,7 @@ CFile::~CFile() {
|
||||
|
||||
void CFile::SetFileName(const CString& sLongName) {
|
||||
if (sLongName.Left(2) == "~/") {
|
||||
m_sLongName = CZNC::Get().GetHomePath() + sLongName.substr(1);
|
||||
m_sLongName = CFile::GetHomePath() + sLongName.substr(1);
|
||||
} else
|
||||
m_sLongName = sLongName;
|
||||
|
||||
@@ -426,11 +428,32 @@ CString CFile::GetDir() const {
|
||||
return sDir;
|
||||
}
|
||||
|
||||
void CFile::InitHomePath(const CString& sFallback) {
|
||||
const char *home = getenv("HOME");
|
||||
|
||||
m_sHomePath.clear();
|
||||
if (home) {
|
||||
m_sHomePath = home;
|
||||
}
|
||||
|
||||
if (m_sHomePath.empty()) {
|
||||
const struct passwd* pUserInfo = getpwuid(getuid());
|
||||
|
||||
if (pUserInfo) {
|
||||
m_sHomePath = pUserInfo->pw_dir;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_sHomePath.empty()) {
|
||||
m_sHomePath = sFallback;
|
||||
}
|
||||
}
|
||||
|
||||
CString CDir::ChangeDir(const CString& sPath, const CString& sAdd, const CString& sHome) {
|
||||
CString sHomeDir(sHome);
|
||||
|
||||
if (sHomeDir.empty()) {
|
||||
sHomeDir = CZNC::Get().GetHomePath();
|
||||
sHomeDir = CFile::GetHomePath();
|
||||
}
|
||||
|
||||
if (sAdd == "~") {
|
||||
|
||||
@@ -120,6 +120,9 @@ public:
|
||||
CString GetShortName() const;
|
||||
CString GetDir() const;
|
||||
|
||||
static void InitHomePath(const CString& sFallback);
|
||||
static const CString& GetHomePath() { return m_sHomePath; }
|
||||
|
||||
private:
|
||||
// fcntl() locking wrapper
|
||||
bool Lock(int iType, bool bBlocking);
|
||||
@@ -127,6 +130,8 @@ private:
|
||||
CString m_sBuffer;
|
||||
int m_iFD;
|
||||
|
||||
static CString m_sHomePath;
|
||||
|
||||
protected:
|
||||
CString m_sLongName; //!< Absolute filename (m_sPath + "/" + m_sShortName)
|
||||
CString m_sShortName; //!< Filename alone, without path
|
||||
|
||||
24
znc.cpp
24
znc.cpp
@@ -12,7 +12,6 @@
|
||||
#include "Server.h"
|
||||
#include "User.h"
|
||||
#include "Listener.h"
|
||||
#include <pwd.h>
|
||||
#include <list>
|
||||
|
||||
namespace
|
||||
@@ -418,8 +417,6 @@ bool CZNC::AllowConnectionFrom(const CString& sIP) const {
|
||||
}
|
||||
|
||||
void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) {
|
||||
char *home;
|
||||
|
||||
// If the bin was not ran from the current directory, we need to add that dir onto our cwd
|
||||
CString::size_type uPos = sArgvPath.rfind('/');
|
||||
if (uPos == CString::npos)
|
||||
@@ -428,27 +425,10 @@ void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) {
|
||||
m_sCurPath = CDir::ChangeDir("./", sArgvPath.Left(uPos), "");
|
||||
|
||||
// Try to set the user's home dir, default to binpath on failure
|
||||
home = getenv("HOME");
|
||||
|
||||
m_sHomePath.clear();
|
||||
if (home) {
|
||||
m_sHomePath = home;
|
||||
}
|
||||
|
||||
if (m_sHomePath.empty()) {
|
||||
struct passwd* pUserInfo = getpwuid(getuid());
|
||||
|
||||
if (pUserInfo) {
|
||||
m_sHomePath = pUserInfo->pw_dir;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_sHomePath.empty()) {
|
||||
m_sHomePath = m_sCurPath;
|
||||
}
|
||||
CFile::InitHomePath(m_sCurPath);
|
||||
|
||||
if (sDataDir.empty()) {
|
||||
m_sZNCPath = m_sHomePath + "/.znc";
|
||||
m_sZNCPath = CFile::GetHomePath() + "/.znc";
|
||||
} else {
|
||||
m_sZNCPath = sDataDir;
|
||||
}
|
||||
|
||||
3
znc.h
3
znc.h
@@ -99,7 +99,7 @@ public:
|
||||
CString GetSkinName() const { return m_sSkinName; }
|
||||
const CString& GetStatusPrefix() const { return m_sStatusPrefix; }
|
||||
const CString& GetCurPath() const { if (!CFile::Exists(m_sCurPath)) { CDir::MakeDir(m_sCurPath); } return m_sCurPath; }
|
||||
const CString& GetHomePath() const { if (!CFile::Exists(m_sHomePath)) { CDir::MakeDir(m_sHomePath); } return m_sHomePath; }
|
||||
const CString& GetHomePath() const { return CFile::GetHomePath(); }
|
||||
const CString& GetZNCPath() const { if (!CFile::Exists(m_sZNCPath)) { CDir::MakeDir(m_sZNCPath); } return m_sZNCPath; }
|
||||
CString GetConfPath(bool bAllowMkDir = true) const;
|
||||
CString GetUserPath() const;
|
||||
@@ -165,7 +165,6 @@ protected:
|
||||
CSockManager m_Manager;
|
||||
|
||||
CString m_sCurPath;
|
||||
CString m_sHomePath;
|
||||
CString m_sZNCPath;
|
||||
|
||||
CString m_sConfigFile;
|
||||
|
||||
Reference in New Issue
Block a user