added support for openoffice and word + optimized decomp temp dir usage
This commit is contained in:
+8
-1
@@ -2,7 +2,7 @@ include ../mk/sysconf
|
||||
|
||||
BIGLIB = ../lib/librcl.a
|
||||
|
||||
PROGS = smallut trfstreewalk trpathut transcode trmimeparse trexecmd
|
||||
PROGS = wipedir smallut trfstreewalk trpathut transcode trmimeparse trexecmd
|
||||
all: $(PROGS)
|
||||
|
||||
FSTREEWALK_OBJS= trfstreewalk.o fstreewalk.o pathut.o
|
||||
@@ -44,5 +44,12 @@ smallut : $(SMALLUT_OBJS)
|
||||
trsmallut.o : ../utils/smallut.cpp
|
||||
$(CXX) $(CXXFLAGS) -DTEST_SMALLUT -c -o trsmallut.o \
|
||||
smallut.cpp
|
||||
|
||||
WIPEDIR_OBJS= trwipedir.o $(BIGLIB)
|
||||
wipedir : $(WIPEDIR_OBJS)
|
||||
$(CXX) $(CXXFLAGS) -o wipedir $(WIPEDIR_OBJS) $(LIBICONV)
|
||||
trwipedir.o : ../utils/wipedir.cpp
|
||||
$(CXX) $(CXXFLAGS) -DTEST_WIPEDIR -c -o trwipedir.o \
|
||||
wipedir.cpp
|
||||
clean:
|
||||
rm -f *.o $(PROGS)
|
||||
|
||||
+40
-1
@@ -1,14 +1,53 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.2 2005-02-04 09:39:44 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.3 2005-02-09 12:07:30 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#ifndef TEST_SMALLUT
|
||||
#include <string>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "smallut.h"
|
||||
#include "debuglog.h"
|
||||
#include "pathut.h"
|
||||
|
||||
#define MIN(A,B) ((A)<(B)?(A):(B))
|
||||
|
||||
bool maketmpdir(string& tdir)
|
||||
{
|
||||
const char *tmpdir = getenv("RECOLL_TMPDIR");
|
||||
if (!tmpdir)
|
||||
tmpdir = getenv("TMPDIR");
|
||||
if (!tmpdir)
|
||||
tmpdir = "/tmp";
|
||||
tdir = tmpdir;
|
||||
path_cat(tdir, "rcltmpXXXXXX");
|
||||
{
|
||||
char *cp = strdup(tdir.c_str());
|
||||
if (!cp) {
|
||||
LOGERR(("maketmpdir: out of memory (for file name !)\n"));
|
||||
tdir.erase();
|
||||
return false;
|
||||
}
|
||||
if (!mktemp(cp)) {
|
||||
free(cp);
|
||||
LOGERR(("maketmpdir: mktemp failed\n"));
|
||||
tdir.erase();
|
||||
return false;
|
||||
}
|
||||
tdir = cp;
|
||||
free(cp);
|
||||
}
|
||||
|
||||
if (mkdir(tdir.c_str(), 0700) < 0) {
|
||||
LOGERR(("maketmpdir: mkdir %s failed\n", tdir.c_str()));
|
||||
tdir.erase();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int stringicmp(const string & s1, const string& s2)
|
||||
{
|
||||
string::const_iterator it1 = s1.begin();
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef _SMALLUT_H_INCLUDED_
|
||||
#define _SMALLUT_H_INCLUDED_
|
||||
/* @(#$Id: smallut.h,v 1.2 2005-02-04 09:39:44 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: smallut.h,v 1.3 2005-02-09 12:07:30 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
@@ -9,4 +9,6 @@ extern int stringicmp(const string& s1, const string& s2);
|
||||
extern int stringlowercmp(const string& alreadylower, const string& s2);
|
||||
extern int stringuppercmp(const string& alreadyupper, const string& s2);
|
||||
|
||||
extern bool maketmpdir(string& tdir);
|
||||
|
||||
#endif /* _SMALLUT_H_INCLUDED_ */
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: wipedir.cpp,v 1.1 2005-02-09 12:07:30 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#ifndef TEST_WIPEDIR
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "pathut.h"
|
||||
#include "wipedir.h"
|
||||
|
||||
int wipedir(const string& dir)
|
||||
{
|
||||
struct stat st;
|
||||
int statret;
|
||||
int ret = -1;
|
||||
|
||||
statret = stat(dir.c_str(), &st);
|
||||
if (statret == -1) {
|
||||
LOGERR(("wipedir: cant stat %s, errno %d\n", dir.c_str(), errno));
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
LOGERR(("wipedir: %s not a directory\n", dir.c_str()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (access(dir.c_str(), R_OK|W_OK|X_OK) < 0) {
|
||||
LOGERR(("wipedir: no write access to %s\n", dir.c_str()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
DIR *d = opendir(dir.c_str());
|
||||
if (d == 0) {
|
||||
LOGERR(("wipedir: cant opendir %s, errno %d\n", dir.c_str(), errno));
|
||||
return -1;
|
||||
}
|
||||
int remaining = 0;
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(d)) != 0) {
|
||||
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
||||
continue;
|
||||
|
||||
string fn = dir;
|
||||
path_cat(fn, ent->d_name);
|
||||
|
||||
struct stat st;
|
||||
int statret = stat(fn.c_str(), &st);
|
||||
if (statret == -1) {
|
||||
LOGERR(("wipedir: cant stat %s, errno %d\n", fn.c_str(), errno));
|
||||
goto out;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
remaining++;
|
||||
} else {
|
||||
if (unlink(fn.c_str()) < 0) {
|
||||
LOGERR(("wipedir: cant unlink %s, errno %d\n",
|
||||
fn.c_str(), errno));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = remaining;
|
||||
out:
|
||||
if (d)
|
||||
closedir(d);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#else // FILEUT_TEST
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "wipedir.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: wipedir <dir>\n");
|
||||
exit(1);
|
||||
}
|
||||
string dir = argv[1];
|
||||
int cnt = wipedir(dir);
|
||||
printf("wipedir returned %d\n", cnt);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _FILEUT_H_INCLUDED_
|
||||
#define _FILEUT_H_INCLUDED_
|
||||
/* @(#$Id: wipedir.h,v 1.1 2005-02-09 12:07:30 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Remove all files inside directory (not recursive).
|
||||
* @return 0 if ok, count of remaining entries (ie: subdirs), or -1 for error
|
||||
*/
|
||||
int wipedir(const std::string& dirname);
|
||||
|
||||
#endif /* _FILEUT_H_INCLUDED_ */
|
||||
Reference in New Issue
Block a user