summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--hadori.C29
-rw-r--r--inode.h53
3 files changed, 29 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index faad8fa..9776253 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ hadori.1: hadori
help2man -n $< -o $@ -N ./$<
hadori: hadori.o
-hadori.o: hadori.C inode.h version.h
+hadori.o: hadori.C version.h
version.h:
test ! -d .git || git describe | sed 's/^\(.*\)$$/#define HADORI_VERSION "hadori \1"/' > $@
diff --git a/hadori.C b/hadori.C
index 4867648..d0b19ab 100644
--- a/hadori.C
+++ b/hadori.C
@@ -26,6 +26,7 @@ namespace po = boost::program_options;
#include <unordered_map>
#include <iostream>
#include <sstream>
+#include <fstream>
#include <cstdlib>
#include <cstring>
@@ -35,7 +36,6 @@ namespace po = boost::program_options;
#include <dirent.h>
#include <sysexits.h>
-#include "inode.h"
#include "version.h"
// needed for equal_range and range-for
@@ -51,6 +51,33 @@ template<typename T> T& end(pair<T,T> & ip) {
po::variables_map config;
std::ostream debug(std::clog.rdbuf()), verbose(std::clog.rdbuf()), error(std::clog.rdbuf());
+struct inode {
+ std::string const filename;
+ struct stat const stat;
+};
+
+inline bool compare (inode const & l, inode const & r) {
+ char lbuffer[1 << 14];
+ char rbuffer[1 << 14];
+ std::ifstream lf(l.filename.c_str());
+ std::ifstream rf(r.filename.c_str());
+
+ while (not lf.eof()) {
+ lf.read(lbuffer, sizeof(lbuffer));
+ rf.read(rbuffer, sizeof(rbuffer));
+ if (lf.gcount() != rf.gcount())
+ return false;
+ if (memcmp(lbuffer, rbuffer, lf.gcount()))
+ return false;
+ }
+ return true;
+}
+
+inline std::ostream& operator<< (std::ostream& os, inode const & i) {
+ os << "Inode " << i.stat.st_ino << ", represented by " << i.filename;
+ return os;
+}
+
void do_link (inode const & i, std::string const & other) {
if (!link(i.filename.c_str(), other.c_str())) {
error << "linking " << i << " to " << other << " succeeded before unlinking (race condition)" << std::endl;
diff --git a/inode.h b/inode.h
deleted file mode 100644
index c9768d2..0000000
--- a/inode.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2011 Timo Weingärtner <timo@tiwe.de>
- *
- * This file is part of hadori.
- *
- * hadori is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Foobar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with hadori. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <string>
-#include <ostream>
-#include <fstream>
-
-#include <cstring>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-struct inode {
- std::string const filename;
- struct stat const stat;
-};
-
-inline bool compare (inode const & l, inode const & r) {
- char lbuffer[1 << 14];
- char rbuffer[1 << 14];
- std::ifstream lf(l.filename.c_str());
- std::ifstream rf(r.filename.c_str());
-
- while (not lf.eof()) {
- lf.read(lbuffer, sizeof(lbuffer));
- rf.read(rbuffer, sizeof(rbuffer));
- if (lf.gcount() != rf.gcount())
- return false;
- if (memcmp(lbuffer, rbuffer, lf.gcount()))
- return false;
- }
- return true;
-}
-
-inline std::ostream& operator<< (std::ostream& os, inode const & i) {
- os << "Inode " << i.stat.st_ino << ", represented by " << i.filename;
- return os;
-}