00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "CSConfig.h"
00030
00031 #include <string.h>
00032
00033 #include "CSStrUtil.h"
00034 #include "CSPath.h"
00035 #include "CSDirectory.h"
00036 #include "CSGlobal.h"
00037
00038
00039
00040
00041
00042
00043 void CSDirectory::print(CSOutputStream *out)
00044 {
00045 char buffer[500];
00046 char number[50];
00047 bool is_dir;
00048 off64_t size;
00049 CSTime mod_time;
00050 char *str_time;
00051
00052 while (next()) {
00053 info(&is_dir, &size, &mod_time);
00054 if (is_dir)
00055 cs_strcpy(500, buffer, "D");
00056 else
00057 cs_strcpy(500, buffer, "f");
00058 snprintf(number, 50, "%8llu ", (unsigned long long) size);
00059 cs_strcat(500, buffer, number);
00060 str_time = mod_time.getCString();
00061 cs_strcat(500, buffer, str_time);
00062 cs_strcat(500, buffer, " ");
00063 cs_strcat(500, buffer, name());
00064 out->printLine(buffer);
00065 }
00066 }
00067
00068 void CSDirectory::deleteEntry()
00069 {
00070 char path[PATH_MAX];
00071
00072 enter_();
00073
00074 getEntryPath(path, PATH_MAX);
00075
00076 CSPath *cs_path = CSPath::newPath(path);
00077 push_(cs_path);
00078 cs_path->removeFile();
00079 release_(cs_path);
00080
00081 exit_();
00082 }
00083
00084 const char *CSDirectory::name()
00085 {
00086 return entryName();
00087 }
00088
00089 bool CSDirectory::isFile()
00090 {
00091 return entryIsFile();
00092 }
00093
00094 off64_t CSDirectory::getSize()
00095 {
00096 char path[PATH_MAX];
00097
00098 getEntryPath(path, PATH_MAX);
00099
00100 return CSPath::getSize(path);
00101 }
00102
00103 void CSDirectory::info(bool *is_dir, off64_t *size, CSTime *mod_time)
00104 {
00105 char path[PATH_MAX];
00106
00107 getEntryPath(path, PATH_MAX);
00108
00109 CSPath::info(path, is_dir, size, mod_time);
00110 }
00111
00112 bool CSDirectory::exists()
00113 {
00114 CSPath *path;
00115 bool yup;
00116
00117 enter_();
00118 path = CSPath::newPath(RETAIN(sd_path));
00119 push_(path);
00120 yup = path->exists();
00121 release_(path);
00122 return_(yup);
00123 }
00124
00125 CSDirectory *CSDirectory::newDirectory(CSString *path)
00126 {
00127 CSDirectory *dir;
00128
00129 if (!(dir = new CSDirectory())) {
00130 path->release();
00131 CSException::throwOSError(CS_CONTEXT, ENOMEM);
00132 }
00133 dir->sd_path = path;
00134 return dir;
00135 }
00136
00137 CSDirectory *CSDirectory::newDirectory(CSPath *path)
00138 {
00139 CSDirectory *dir;
00140 enter_();
00141
00142 push_(path);
00143 dir = newDirectory(RETAIN(path->getString()));
00144 release_(path);
00145 return_(dir);
00146 }
00147
00148 CSDirectory *CSDirectory::newDirectory(const char *path)
00149 {
00150 return newDirectory(CSString::newString(path));
00151 }
00152
00153