Skip to content

Commit

Permalink
don't screw up hardlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
darealshinji committed Aug 22, 2014
1 parent bba821a commit bed9cea
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/patchelfmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,9 @@ template < ElfFileParams > void ElfFile < ElfFileParamNames >::sortShdrs()
wri(hdr->e_shstrndx, findSection3(shstrtabName));
}

static void writeFile(string fileName, mode_t fileMode)
static void writeFile(string fileName)
{
string fileName2 = fileName + "_patchelfmod_tmp";

int fd = open(fileName2.c_str(),
O_CREAT | O_TRUNC | O_WRONLY, 0700);
int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY, 0700);
if (fd == -1)
error("open");

Expand All @@ -258,21 +255,6 @@ static void writeFile(string fileName, mode_t fileMode)

if (close(fd) != 0)
error("close");

#if defined(HAVE_ATTR_COPY_FILE)
if (attr_copy_file(fileName.c_str(), fileName2.c_str(), 0, 0) != 0)
error("attr_copy_file");
#endif
#if defined(HAVE_PERM_COPY_FILE)
if (perm_copy_file(fileName.c_str(), fileName2.c_str(), 0) != 0)
error("perm_copy_file");
#else
if (chmod(fileName2.c_str(), fileMode) != 0)
error("chmod");
#endif

if (rename(fileName2.c_str(), fileName.c_str()) != 0)
error("rename");
}

static void writeFileBackup(string fileName, mode_t fileMode)
Expand Down Expand Up @@ -1416,7 +1398,7 @@ template < class ElfFile >
if (saveBackup)
writeFileBackup(fileName, fileMode);
elfFile.rewriteSections();
writeFile(fileName, fileMode);
writeFile(fileName);
}
}

Expand Down

0 comments on commit bed9cea

Please sign in to comment.