summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-30 15:15:08 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-30 15:15:08 +0200
commit5632ddb849821bf8c4fac9f4aa8c4779575eef97 (patch)
treec0f5cdeabec71de882f7d6dcbfffc0daeb0c961a /lib
parent0a901ba3e651a70984e980f61619b005031a71f0 (diff)
fix all instances of dent->d_type == DT_REG checks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Plugins/FileTransfer.cpp9
-rw-r--r--lib/Utils/DebugDump.cpp14
-rw-r--r--lib/Utils/xfuncs.cpp19
3 files changed, 27 insertions, 15 deletions
diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp
index 08d915d..9c2f3c5 100644
--- a/lib/Plugins/FileTransfer.cpp
+++ b/lib/Plugins/FileTransfer.cpp
@@ -137,13 +137,12 @@ static void traverse_directory(const char * directory, void * something,
dp = opendir(directory);
while ((dirp = readdir(dp)) != NULL)
{
- if (dirp->d_type == DT_REG)
+ if (is_regular_file(dirp, directory))
{
- complete_name[0] = '\0';
end = stpcpy(complete_name, directory);
if (end[-1] != '/')
{
- end = stpcpy(end, "/");
+ *end++ = '/';
}
end = stpcpy(end, dirp->d_name);
@@ -292,7 +291,8 @@ void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs)
dirlist.open(FILETRANSFER_DIRLIST, fstream::out | fstream::app );
dirlist << pActiveDir << endl;
dirlist.close();
- } else if(pArgs == "one")
+ }
+ else if (pArgs == "one")
{
/* just send one archive */
gethostname(hostname,HBLEN);
@@ -312,7 +312,6 @@ void CFileTransfer::Run(const std::string& pActiveDir, const std::string& pArgs)
}
else
{
-
gethostname(hostname,HBLEN);
dirlist.open(FILETRANSFER_DIRLIST, fstream::in);
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 6056443..43eb324 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -484,16 +484,10 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool
struct dirent *dent;
while ((dent = readdir(m_pGetNextFileDir)) != NULL)
{
- struct stat statbuf;
- std::string fullname = m_sDebugDumpDir + "/" + dent->d_name;
-
- /* some filesystems do not report the type! they report DT_UNKNOWN */
- if (dent->d_type == DT_REG
- || (dent->d_type == DT_UNKNOWN
- && lstat(fullname.c_str(), &statbuf) == 0
- && S_ISREG(statbuf.st_mode)
- )
- ) {
+ if (is_regular_file(dent, m_sDebugDumpDir.c_str()))
+ {
+ std::string fullname = m_sDebugDumpDir + "/" + dent->d_name;
+
pFileName = dent->d_name;
if (IsTextFile(fullname))
{
diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp
index f447b8f..d256c19 100644
--- a/lib/Utils/xfuncs.cpp
+++ b/lib/Utils/xfuncs.cpp
@@ -286,3 +286,22 @@ void xunlink(const char *pathname)
if (unlink(pathname))
perror_msg_and_die("can't remove file '%s'", pathname);
}
+
+/* Just testing dent->d_type == DT_REG is wrong: some filesystems
+ * do not report the type, they report DT_UNKNOWN for every dirent
+ * (and this is not a bug in filesystem, this is allowed by standards).
+ */
+int is_regular_file(struct dirent *dent, const char *dirname)
+{
+ if (dent->d_type == DT_REG)
+ return 1;
+ if (dent->d_type != DT_UNKNOWN)
+ return 0;
+
+ char *fullname = xasprintf("%s/%s", dirname, dent->d_name);
+ struct stat statbuf;
+ int r = lstat(fullname, &statbuf);
+ free(fullname);
+
+ return r == 0 && S_ISREG(statbuf.st_mode);
+}