Drizzled Public API Documentation

CSPath.h

00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Original author: Paul McCullagh
00020  * Continued development: Barry Leslie
00021  *
00022  * 2007-06-07
00023  *
00024  * CORE SYSTEM:
00025  * Basic file system path.
00026  *
00027  */
00028 
00029 #pragma once
00030 #ifndef __CSPATH_H__
00031 #define __CSPATH_H__
00032 
00033 #ifdef OS_UNIX
00034 #include <limits.h>
00035 #endif
00036 
00037 #include "CSDefs.h"
00038 #include "CSTime.h"
00039 #include "CSDefs.h"
00040 #include "CSString.h"
00041 #include "CSSys.h"
00042 
00043 class CSFile;
00044 class CSDirectory;
00045 
00046 class CSPath : public CSRefObject, public CSSys {
00047 public:
00048   virtual CSFile *createFile(int mode);
00049 
00050   virtual void copyFile(CSPath *to_file, bool overwrite);
00051 
00052   /*
00053    * Recursively creates as many directories as required.
00054    */
00055   virtual void makePath();
00056 
00057   virtual void copyDir(CSPath *to_dir, bool overwrite);
00058 
00059   /* Return true of the directory is a symbolic link. */
00060   virtual bool isLink();
00061 
00062   /* Return true of the directory is empty. */
00063   virtual bool isEmpty();
00064 
00065   /* Delete the contents of a directory */
00066   virtual void emptyDir();
00067   
00068   /* Recursively delete the contents of a directory */
00069   virtual void emptyPath();
00070   
00071   /* Copy a file or directory to the specified location. */
00072   virtual void copyTo(CSPath *to_path, bool overwrite);
00073 
00074   virtual void moveTo(CSPath *to_path);
00075 
00076   /*
00077    * Remove a file or directory (even if not empty).
00078    */
00079   virtual void remove();
00080 
00081   /* Create an empty file. */
00082   virtual void touch(bool create_path = false);
00083 
00084   virtual CSString *getString();
00085 
00086   virtual const char *getCString();
00087 
00088   virtual const char *getNameCString();
00089 
00090   //virtual CSPath *clone() const;
00091 
00092   friend class TDPath;
00093   
00094   virtual bool exists(bool *is_dir);
00095 
00096   virtual bool exists() { return exists(NULL); }
00097 
00098   static void info(const char *path, bool *is_dir, off64_t *size, CSTime *mod_time);
00099 
00100   virtual void info(bool *is_dir, off64_t *size, CSTime *mod_time);
00101 
00102   static off64_t getSize(const char *path);
00103   
00104   virtual off64_t getSize();
00105 
00106   virtual bool isDir();
00107 
00108   virtual CSFile *openFile(int mode);
00109 
00110   /*
00111    * Remove a file.
00112    */
00113   virtual void removeFile();
00114 
00115   /*
00116    * Creates a directory assuming the directory path exists.
00117    */
00118   virtual void makeDir();
00119 
00120   virtual CSDirectory *openDirectory();
00121 
00122   virtual void removeDir();
00123 
00124   virtual void rename(const char *name);
00125 
00126   /*
00127    * Renames one path to another.
00128    * The destination path may not exist.
00129    */
00130   virtual void move(CSPath *to_path);
00131   
00132   CSPath *getCWD();
00133 
00134   static CSPath *getSystemCWD();
00135 
00136   /* Create a new path given an absolute and a relative path: */
00137   static CSPath *newPath(const char *path);
00138   static CSPath *newPath(CSString *path);
00139 
00140   /* Create a path relative to the given 'cwd' */
00141   static CSPath *newPath(CSPath *cwd, const char *path);
00142   static CSPath *newPath(CSString *cwd, const char *path);
00143   static CSPath *newPath(const char *cwd, CSString *path);
00144   static CSPath *newPath(const char *cwd, const char *path);
00145 
00146 private:
00147   CSFile *try_CreateAndOpen(CSThread *self, int mode, bool retry);
00148   static CSLock iRename_lock;
00149   CSPath():iPath(NULL) { }
00150 
00151   virtual ~CSPath();
00152 
00153   CSString *iPath;
00154 
00155   static CSPath *iCWD;
00156 };
00157 
00158 #endif