Rename get_dir_size() to get_dir_count()
[libi2ncommon] / src / filefunc.hxx
index c0c01f7..6051707 100644 (file)
@@ -1,6 +1,24 @@
+/*
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
+
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
 /***************************************************************************
  *   Copyright (C) 2004-2008 by Intra2net AG                                    *
- *   info@intra2net.com                                                    *
  *                                                                         *
  ***************************************************************************/
 
@@ -8,6 +26,13 @@
 #define __FILEFUNC_HXX
 
 #include "userfunc.hpp"
+#include <set>
+
+// make sure we have proper large file support
+#include <features.h>
+#ifndef _GNU_SOURCE
+    #define _GNU_SOURCE
+#endif
 
 namespace I2n
 {
@@ -42,6 +67,9 @@ public:
    time_t  mtime() const { return Mtime; }
    time_t  ctime() const { return Ctime; }
 
+   // bytes used on disk, calculated from allocated blocks
+   long long bytes_on_disk() const { return BytesOnDisk; }
+
    nlink_t num_hard_links() const { return NumLinks; }
    dev_t   device_type() const { return DeviceType; }
    time_t  last_modified_time() const { return Mtime; }
@@ -106,6 +134,7 @@ protected:
    gid_t   Gid;
    dev_t   DeviceType;
    off_t   Size;
+   long long BytesOnDisk;
    time_t  Atime;
    time_t  Mtime;
    time_t  Ctime;
@@ -127,11 +156,13 @@ protected:
 bool path_exists(const std::string& path);
 bool file_exists(const std::string& path);
 long file_size (const std::string &name);
+bool file_content_differs(const std::string &old_filename, const std::string &new_filename);
 
 time_t file_mtime(const std::string& path);
 
 bool get_dir(const std::string& path, std::vector< std::string >& result, bool include_dot_names= false );
 std::vector< std::string > get_dir(const std::string& path, bool include_dot_names= false );
+int get_dir_count(const std::string& path, bool include_dot_names= false );
 
 bool unlink(const std::string& path);
 
@@ -141,9 +172,10 @@ std::string read_link(const std::string& path);
 
 std::string read_file(const std::string& path);
 
-bool write_file(const std::string& path, const std::string& data);
+bool write_file(const std::string& path, const std::string& data, bool trunc=true);
 
 bool copy_file(const std::string& src, const std::string& dest);
+bool copy_stream(std::istream& is, std::ostream& os);
 
 std::string basename(const std::string& path);
 
@@ -151,10 +183,35 @@ std::string dirname(const std::string& path);
 
 std::string normalize_path(const std::string& path);
 
+bool dirsync(const std::string& path);
+
 bool chmod(const std::string& path, int mode);
 bool chown(const std::string& path, const I2n::User& user, const I2n::Group& group= I2n::Group());
 
-bool recursive_delete(const std::string &path, std::string *error=NULL);
+bool recursive_delete(const std::string &path,
+                      bool keep_parent_dir=false,
+                      std::string *error=NULL);
+
+std::string mkdtemp(const std::string &path_template, std::string *error=NULL);
+// mkstemp: see tmpfstream
+
+bool mkdir(const std::string &path, const mode_t &mode=0700, std::string *error=NULL);
+bool rmdir(const std::string &path, std::string *error=NULL);
+
+std::string getcwd();
+bool chdir(const std::string &path, std::string *error=NULL);
+
+mode_t umask(mode_t mask);
+
+long long get_free_diskspace(const std::string& path);
+long long du(const std::string &path, std::string *error=NULL);
+
+/*
+** more specialized tool function(s)
+*/
+bool remove_unlisted_files(const std::string &directory,
+                           const std::set<std::string> &keep_files,
+                           const std::string &prefix="");
 
 }