mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-26 23:13:00 +02:00
CFileHelpers::copyFile: Rewrite mode handling
Origin commit data
------------------
Commit: 64b5d36c52
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-09-03 (Sat, 03 Sep 2016)
This commit is contained in:
@@ -554,12 +554,36 @@ CFileHelpers* CFileHelpers::getInstance()
|
|||||||
return FileHelpers;
|
return FileHelpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t mode)
|
bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t forceMode/*=0*/)
|
||||||
{
|
{
|
||||||
doCopyFlag = true;
|
doCopyFlag = true;
|
||||||
unlink(Dst);
|
|
||||||
|
/*
|
||||||
|
set mode for Dst
|
||||||
|
----------------
|
||||||
|
when forceMode==0 (default) then
|
||||||
|
when Dst exists
|
||||||
|
mode = mode from Dst
|
||||||
|
else
|
||||||
|
mode = mode from Src
|
||||||
|
else
|
||||||
|
mode = forceMode
|
||||||
|
*/
|
||||||
|
mode_t mode = forceMode & 0x0FFF;
|
||||||
|
if (mode == 0) {
|
||||||
|
static struct stat FileInfo;
|
||||||
|
const char *f = Dst;
|
||||||
|
if (!file_exists(Dst))
|
||||||
|
f = Src;
|
||||||
|
if (lstat(f, &FileInfo) == -1)
|
||||||
|
return false;
|
||||||
|
mode = FileInfo.st_mode & 0x0FFF;
|
||||||
|
}
|
||||||
|
|
||||||
if ((fd1 = open(Src, O_RDONLY)) < 0)
|
if ((fd1 = open(Src, O_RDONLY)) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
if (file_exists(Dst))
|
||||||
|
unlink(Dst);
|
||||||
if ((fd2 = open(Dst, O_WRONLY | O_CREAT, mode)) < 0) {
|
if ((fd2 = open(Dst, O_WRONLY | O_CREAT, mode)) < 0) {
|
||||||
close(fd1);
|
close(fd1);
|
||||||
return false;
|
return false;
|
||||||
@@ -692,7 +716,7 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
|||||||
std::string save = "";
|
std::string save = "";
|
||||||
if (backupMode && (CExtUpdate::getInstance()->isBlacklistEntry(srcPath)))
|
if (backupMode && (CExtUpdate::getInstance()->isBlacklistEntry(srcPath)))
|
||||||
save = ".save";
|
save = ".save";
|
||||||
copyFile(srcPath, (dstPath + save).c_str(), FileInfo.st_mode & 0x0FFF);
|
copyFile(srcPath, (dstPath + save).c_str()); /* mode is set by copyFile */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -87,7 +87,7 @@ class CFileHelpers
|
|||||||
static CFileHelpers* getInstance();
|
static CFileHelpers* getInstance();
|
||||||
bool doCopyFlag;
|
bool doCopyFlag;
|
||||||
|
|
||||||
bool copyFile(const char *Src, const char *Dst, mode_t mode);
|
bool copyFile(const char *Src, const char *Dst, mode_t forceMode=0);
|
||||||
bool copyDir(const char *Src, const char *Dst, bool backupMode=false);
|
bool copyDir(const char *Src, const char *Dst, bool backupMode=false);
|
||||||
static bool createDir(std::string& Dir, mode_t mode = 755);
|
static bool createDir(std::string& Dir, mode_t mode = 755);
|
||||||
static bool createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);}
|
static bool createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);}
|
||||||
|
Reference in New Issue
Block a user