Skip to content

Commit

Permalink
move temp files to /tmp (fix #131)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Oct 26, 2016
1 parent 871b950 commit 959fd2a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion WinPort/src/PathHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ bool MatchWildcardICE(const char *string, const char *wild) {
void WinPortInitWellKnownEnv()
{
if (!getenv("TEMP")) {
std::string temp = InMyProfile("tmp");
const std::string &temp = InTemp();
mkdir(temp.c_str(), 0777);
setenv("TEMP", temp.c_str(), 1);
}
Expand Down
6 changes: 3 additions & 3 deletions far2l/treelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,11 +2116,11 @@ static void MkTreeName(FARString &out, const wchar_t *RootDir, const char *ext)
int r = sdc_stat(Wide2MB(RootDir).c_str(), &s);
if (r == 0) {
char tmp[128];
sprintf(tmp, "tmp/tree/%llx-%llx.%s",
sprintf(tmp, "tree/%llx-%llx.%s",
(unsigned long long)s.st_rdev, (unsigned long long)s.st_ino, ext);
out = InMyProfile(tmp);
out = InTemp(tmp);
} else {
std::string tmp = InMyProfile("tmp/tree/wtf-");
std::string tmp = InTemp("tree/wtf-");
const std::string &RootMB = Wide2MB(RootDir);
for (char c : RootMB) {
tmp+= (c==GOOD_SLASH) ? '@' : c;
Expand Down
2 changes: 1 addition & 1 deletion far2l/vtcompletor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const char *vtc_inputrc = "set completion-query-items 0\n"


VTCompletor::VTCompletor()
: _vtc_inputrc(InMyProfile("tmp/vtc_inputrc")),
: _vtc_inputrc(InTemp("vtc_inputrc")),
_pipe_stdin(-1), _pipe_stdout(-1), _pid(-1)
{
int fd = open(_vtc_inputrc.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0622);
Expand Down
6 changes: 3 additions & 3 deletions far2l/vtshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor
std::string rc_src, rc_dst, rc_arg;
if (strstr(shell, "/bash")) {
rc_src = std::string(home) + "/.bashrc";
rc_dst = InMyProfile("vtcmd/init.bash");
rc_dst = InTemp("vtcmd/init.bash");
rc_arg = "--rcfile";
}/* else if (strstr(shell, "/zsh")) {
rc_src = std::string(home) + "/.zshrc";
rc_dst = InMyProfile("vtcmd/init.zsh");
rc_dst = InTemp("vtcmd/init.zsh");
rc_arg = "--rcs";
}*/

Expand Down Expand Up @@ -681,7 +681,7 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor
{
char name[128];
sprintf(name, "vtcmd/%x_%p", getpid(), this);
std::string cmd_script = InMyProfile(name);
std::string cmd_script = InTemp(name);
FILE *f = fopen(cmd_script.c_str(), "wt");
if (!f)
return std::string();
Expand Down
1 change: 1 addition & 0 deletions utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ find_package(PkgConfig REQUIRED)
set(SOURCES
src/KeyFileHelper.cpp
src/utils.cpp
src/temp.cpp
src/ZombieControl.cpp
src/ConvertUTF.c
)
Expand Down
1 change: 1 addition & 0 deletions utils/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ size_t StrStartsFrom(const std::string &haystack, const char *needle);
std::string EscapeQuotas(std::string str);

std::string InMyProfile(const char *subpath = NULL, bool create_path = true);
std::string InTemp(const char *subpath = NULL);


void CheckedCloseFD(int &fd);
Expand Down
26 changes: 15 additions & 11 deletions utils/src/temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void GetTempRoot(std::string &path)
return;
}

char *temp = getenv("TEMP");
const char *temp = getenv("TEMP");
if (!temp || stat(temp, &s) == -1 || (s.st_mode & S_IFMT) != S_IFDIR) {
temp = "/tmp";
if (stat(temp, &s) == -1 || (s.st_mode & S_IFMT) != S_IFDIR) {
Expand All @@ -41,32 +41,36 @@ static void GetTempRoot(std::string &path)
path = temp;
path+= GOOD_SLASH;
char buf[128];
sprintf(buf, "%llx_%u", (unsigned long long)geteuid(), i);
sprintf(buf, "far2l_%llx_%u", (unsigned long long)geteuid(), i);
path+= buf;
mkdir(path.c_str(), 0700);
if (stat(temp, &s) == 0 && (s.st_mode & S_IFMT) == S_IFDIR && s.st_uid == geteuid()) {
if (stat(path.c_str(), &s) == 0 &&
(s.st_mode & S_IFMT) == S_IFDIR &&
s.st_uid == geteuid()) {
break;
}

if (i == (unsigned int)-1) {
perror("Can't create temp!");
perror("Can't init temp!");
return;
}
}
s_in_prof_temp = path;
s_ready_temp = path;

}

std::string InTemp(const char *subpath = NULL)
std::string InTemp(const char *subpath)
{
std::string path;
GetTempRoot(path);
out+= GOOD_SLASH;
for (;*subpath; ++subpath) {
if (*subpath == GOOD_SLASH) {
mkdir(path.c_str(), 0700);
path+= GOOD_SLASH;
if (subpath) {
for (;*subpath; ++subpath) {
if (*subpath == GOOD_SLASH) {
mkdir(path.c_str(), 0700);
}
path+= *subpath;
}
path+= subpath;
}

return path;
Expand Down

0 comments on commit 959fd2a

Please sign in to comment.