14 #define TRY_COMMAND(code) \
27 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
28 int alpha_len = strlen(alpha);
31 out = fopen(pathname.c_str(),
"wb");
35 es =
"Could not open file \"";
41 for (count = 0; count < size; count++) {
42 if (fputc(alpha[count % alpha_len], out) == EOF) {
45 es =
"Write error on file \"";
52 if (fclose(out) != 0) {
55 es =
"Close error on file \"";
67 r = system(
"rm -fr ./test-fs.dir");
74 std::cerr <<
"NOTICE: The following check failed: test_cwd()" << std::endl;
75 std::cerr <<
"ceck_cwd = " <<
check_cwd << std::endl;
76 std::cerr <<
" cwd() = " <<
cwd() << std::endl;
90 assert(
reform_path(
"//var//rvm/////") ==
"/var/rvm/");
107 assert(
exists(
"./INSTALL"));
108 assert(!
exists(
"./lkjsdflkjsdf.h"));
131 assert(!
exists(
"./test-fs.dir"));
134 assert(
exists(
"./test-fs.dir"));
141 assert(
exists(
"./test-fs.dir"));
144 assert(!
exists(
"./test-fs.dir"));
151 if (!
exists(
"./test-fs.dir"))
154 assert(
exists(
"./test-fs.dir/file"));
157 assert(!
exists(
"./test-fs.dir/file"));
162 assert(!
exists(
"./test-fs.dir"));
169 assert(!
exists(
"./test-fs.dir"));
172 assert(
exists(
"./test-fs.dir"));
173 assert(
exists(
"./test-fs.dir/etc"));
174 assert(
exists(
"./test-fs.dir/etc/rvm"));
177 assert(
exists(
"./test-fs.dir"));
178 assert(
exists(
"./test-fs.dir/var"));
179 assert(
exists(
"./test-fs.dir/var/rvm"));
187 assert(
exists(
"./test-fs.dir"));
188 assert(
exists(
"./test-fs.dir/etc"));
189 assert(
exists(
"./test-fs.dir/etc/rvm"));
190 assert(
exists(
"./test-fs.dir/var"));
191 assert(
exists(
"./test-fs.dir/var/rvm"));
201 assert(f.is_directory());
207 assert(f.is_regular_file());
209 assert(f.
size() == 1024);
214 assert(f.is_regular_file());
216 assert(f.
size() == 4484);
224 assert(
exists(
"./test-fs.dir/file2"));
227 assert(
exists(
"./test-fs.dir/link-file2"));
232 assert(f.
link() ==
"file2");
241 assert(
exists(
"./test-fs.dir/etc/rvm"));
242 assert(
exists(
"./test-fs.dir/file1"));
243 assert(
exists(
"./test-fs.dir/var/rvm"));
247 assert(
exists(
"./test-fs.dir/link-file1"));
252 assert(f.
link() ==
"file1");
256 "./test-fs.dir/etc/rvm/link-file1"));
258 assert(
exists(
"./test-fs.dir/etc/rvm/link-file1"));
263 assert(f.
link() ==
"../../file1");
267 "./test-fs.dir/etc/rvm/link-rvm-file1"));
269 assert(
exists(
"./test-fs.dir/etc/rvm/link-rvm-file1"));
273 assert(f.
link() ==
"../../var/rvm/file1");
281 subdir.
path(
"./test-fs.dir/etc/rvm",
"l*1");
294 assert(subdir.size() == 6);
295 assert(subdir[0] ==
"etc");
296 assert(subdir[1] ==
"file1");
297 assert(subdir[2] ==
"file2");
298 assert(subdir[3] ==
"link-file1");
299 assert(subdir[4] ==
"link-file2");
300 assert(subdir[5] ==
"var");
304 assert(subdir.size() == 2);
305 assert(subdir[0] ==
"link-file1");
306 assert(subdir[1] ==
"link-file2");
310 assert(subdir.size() == 2);
311 assert(subdir[0] ==
"link-file1");
312 assert(subdir[1] ==
"link-rvm-file1");
316 assert(subdir2.size() == 2);
317 assert(subdir2[0] ==
"link-file1");
318 assert(subdir2[1] ==
"link-rvm-file1");
322 assert(subdir3.size() == 2);
323 assert(subdir3[0] ==
"link-file1");
324 assert(subdir3[1] ==
"link-rvm-file1");
334 assert(dir.size() == 1);
335 assert(dir[0] ==
"./test-fs.dir");
339 assert(dir.size() == 6);
340 assert(dir[0] ==
"./test-fs.dir/etc");
341 assert(dir[1] ==
"./test-fs.dir/file1");
342 assert(dir[2] ==
"./test-fs.dir/file2");
343 assert(dir[3] ==
"./test-fs.dir/link-file1");
344 assert(dir[4] ==
"./test-fs.dir/link-file2");
345 assert(dir[5] ==
"./test-fs.dir/var");
349 assert(dir.size() == 2);
350 assert(dir[0] ==
"./test-fs.dir/etc/rvm/link-file1");
351 assert(dir[1] ==
"./test-fs.dir/etc/rvm/link-rvm-file1");
355 assert(dir.size() == 4);
356 assert(dir[0] ==
"./test-fs.dir/etc/rvm/file1");
357 assert(dir[1] ==
"./test-fs.dir/etc/rvm/link-file1");
358 assert(dir[2] ==
"./test-fs.dir/etc/rvm/link-rvm-file1");
359 assert(dir[3] ==
"./test-fs.dir/var/rvm/file1");
368 assert(!
exists(
"./test-fs.dir"));
375 "./test-fs.dir/dir1a/dir2a/dir3a/file.conf",
376 "./test-fs.dir/dir1a/dir2a/dir3a"
382 "./test-fs.dir/dir1a/dir2a/dir3a/file.conf",
383 "./test-fs.dir/dir1a/dir2a/dir3b"
385 ==
"../dir3a/file.conf"
389 "./test-fs.dir/dir1a/dir2a/dir3a/file.conf",
390 "./test-fs.dir/dir1a/dir2b/dir3b"
392 ==
"../../dir2a/dir3a/file.conf"
396 "./test-fs.dir/dir1a/dir2a/dir3a/file.conf",
397 "./test-fs.dir/dir1b/dir2b/dir3b"
399 ==
"../../../dir1a/dir2a/dir3a/file.conf"
403 "./test-fs.dir/dir1a/dir2a/dir3a/file.conf",
404 "./test-fs.dir.b/dir1b/dir2b/dir3b"
406 ==
"../../../../test-fs.dir/dir1a/dir2a/dir3a/file.conf"
422 assert(system(
"rm -fr ./test-fs.dir") == 0);
424 assert(
exists(
"./test-fs.dir"));
440 out.open(
"./test-fs.dir/lock");
441 assert(out.is_open());
442 out << getpid()+1234 << std::endl;
452 assert((pid = ::fork()) >= 0);
458 assert(system(
"rm -f ./test-fs.dir/lock") == 0);
459 assert(!
exists(
"./test-fs.dir/lock"));
463 assert(sl.
lock() ==
true);
464 while (
exists(
"./test-fs.dir/lock"));
475 assert(!
exists(
"./test-fs.dir/lock"));
479 assert(sl.
lock() ==
true);
488 assert(
exists(
"./test-fs.dir/lock"));
501 assert(!
exists(
"./test-fs.dir/lock"));
503 assert(system(
"rm -fr ./test-fs.dir") == 0);
504 assert(!
exists(
"./test-fs.dir"));
507 int main(
int argc,
char const * argv[])
#define TRY_COMMAND(code)
const pid_t pid(void)
Return the PID of this process.
std::string reform_path(const std::string &a_path)
Reformat a path to remove double slashes.
const std::string cwd(void)
Return the current working directory.
Retrieve information about a filesystem.
void mk_dir(const std::string &a_path)
Create a directory.
void path(const std::string a_path)
Retrieve information about a pathname.
void test_simple_lock(void)
const type & path(const std::string &a_path)
Retrieve a list of paths that match the wildcard path given.
void test_mk_relative_path(void)
const subdirectory test_subdirectory_sub(void)
void path(const std::string &a_path)
Retrieve information about the filesystem on which the given path resides.
bool executable(const std::string &a_path)
Return true if the file or directory exists and is executable.
void create_file(const std::string &pathname, uint32 size)
void mk_dirhier(const std::string a_path)
Recursively create a directory heirarchy.
void test_mk_relative_symlink(void)
bool writable(const std::string &a_path)
Return true if the file or directory exists and is writable.
const std::string link(void) const
If the pathname is a link, return the path it is linked to.
void test_reform_path(void)
bool readable(const std::string &a_path)
Return true if the file or directory exists and is readable.
void test_mk_symlink(void)
Retrieve a list of pathnames that match a given wildcard path.
void lockfile(const std::string &a_lockfile)
Set the lockfile path.
bool exists(const std::string &a_path)
Return true if the file or directory exists.
void test_executable(void)
void test_subdirectory(void)
void rm_dir(const std::string a_path)
Remove a directory.
A simple locking mechanism.
const type & path(const std::string a_path, const std::string a_filter="*")
Return a vector of strings of a list of files in a subdirectory.
void test_mk_dirhier(void)
void test_rm_recursive(void)
void mk_relative_symlink(const std::string a_from, const std::string a_to)
Given a from and to path, create a relative symbolic link.
const pid_type locked_by(void) const
Get the PID of the locking process.
void rm_recursive(const std::string a_path)
Recursively delete the contents of a directory.
Retrieve information about a file or directory.
std::string permute_path(const std::string &a_path)
Reformat a path to remove the begining and trailing slashes, and replace all other slashes with under...
std::string mk_relative_path(const std::string a_path_to, const std::string a_path_from)
Make the path a_path_to relative from a_path_from, where a_path_to and a_path_from are directory name...
void test_filestatus(void)
void test_permute_path(void)
int main(int argc, char const *argv[])
const size_type size(void) const
Return the file size in bytes.
void rm_file(const std::string a_path)
Remove a file.
Retrieve a list of files in a subdirectory that match a given wildcard filename.
void test_filesystem(void)
const bool is_locked(void) const
Find out whether or not the lock is in place.
void test_directory(void)
void mk_symlink(const std::string a_from, const std::string a_to)
Create a symbolic link.