[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
105/118: Remove some duplicate code
From: |
Ludovic Courtès |
Subject: |
105/118: Remove some duplicate code |
Date: |
Tue, 19 May 2015 14:46:00 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit c2b65dd197a1b2e14d517b0b5ff307b149538917
Author: Eelco Dolstra <address@hidden>
Date: Fri Oct 3 22:37:51 2014 +0200
Remove some duplicate code
---
nix/libstore/gc.cc | 8 ++------
nix/libutil/util.cc | 10 ++++++++++
nix/libutil/util.hh | 2 ++
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index 4babea4..05d332f 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -301,12 +301,8 @@ static void findRoots(StoreAPI & store, const Path & path,
unsigned char type, R
{
try {
- if (type == DT_UNKNOWN) {
- struct stat st = lstat(path);
- if (S_ISDIR(st.st_mode)) type = DT_DIR;
- else if (S_ISLNK(st.st_mode)) type = DT_LNK;
- else if (S_ISREG(st.st_mode)) type = DT_REG;
- }
+ if (type == DT_UNKNOWN)
+ type = getFileType(path);
if (type == DT_DIR) {
for (auto & i : readDirectory(path))
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 9af42a1..ad3b3c3 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -223,6 +223,16 @@ DirEntries readDirectory(const Path & path)
}
+unsigned char getFileType(const Path & path)
+{
+ struct stat st = lstat(path);
+ if (S_ISDIR(st.st_mode)) return DT_DIR;
+ if (S_ISLNK(st.st_mode)) return DT_LNK;
+ if (S_ISREG(st.st_mode)) return DT_REG;
+ return DT_UNKNOWN;
+}
+
+
string readFile(int fd)
{
struct stat st;
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh
index 7e538ea..418d76d 100644
--- a/nix/libutil/util.hh
+++ b/nix/libutil/util.hh
@@ -77,6 +77,8 @@ typedef vector<DirEntry> DirEntries;
DirEntries readDirectory(const Path & path);
+unsigned char getFileType(const Path & path);
+
/* Read the contents of a file into a string. */
string readFile(int fd);
string readFile(const Path & path, bool drain = false);
- 101/118: On Linux, disable address space randomization, (continued)
- 101/118: On Linux, disable address space randomization, Ludovic Courtès, 2015/05/19
- 91/118: Use regular file GC roots if possible, Ludovic Courtès, 2015/05/19
- 102/118: Remove bogus comment, Ludovic Courtès, 2015/05/19
- 80/118: Make readDirectory() return inode / file type, Ludovic Courtès, 2015/05/19
- 94/118: Doh, Ludovic Courtès, 2015/05/19
- 96/118: fix disappearing bash arguments, Ludovic Courtès, 2015/05/19
- 104/118: createDirs(): Handle ‘path’ being a symlink, Ludovic Courtès, 2015/05/19
- 103/118: nix-daemon: Close unnecessary fd, Ludovic Courtès, 2015/05/19
- 97/118: Introduce allowedRequisites feature, Ludovic Courtès, 2015/05/19
- 113/118: Clean up temp roots in a more C++ way, Ludovic Courtès, 2015/05/19
- 105/118: Remove some duplicate code,
Ludovic Courtès <=
- 108/118: Improve error message if the daemon worker fails to start, Ludovic Courtès, 2015/05/19
- 100/118: Settings: Add bool get(), Ludovic Courtès, 2015/05/19
- 106/118: Improved error message when encountering unsupported file types, Ludovic Courtès, 2015/05/19
- 114/118: nix-daemon: Call exit(), not _exit(), Ludovic Courtès, 2015/05/19
- 99/118: Add an 'optimiseStore' remote procedure call., Ludovic Courtès, 2015/05/19
- 107/118: Fix build on gcc < 4.7, Ludovic Courtès, 2015/05/19
- 98/118: Add disallowedReferences / disallowedRequisites, Ludovic Courtès, 2015/05/19
- 110/118: Make ~DerivationGoal more reliable, Ludovic Courtès, 2015/05/19
- 111/118: Don't use ADDR_LIMIT_3GB, Ludovic Courtès, 2015/05/19
- 115/118: Disable vacuuming the DB after garbage collection, Ludovic Courtès, 2015/05/19