aboutsummaryrefslogtreecommitdiff
path: root/build2/filesystem.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-09-05 00:00:14 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-09-05 11:38:25 +0300
commit9c0dc1f4957420688cf2c1afe79fa2f53f2a6abf (patch)
tree04f37bc105817be5399b060c05afb63d6c7e5a28 /build2/filesystem.cxx
parent58a05fc84029acdb711b40cf2cee09a0b2202bf7 (diff)
Create .buildignore file in testscript root working directory
Diffstat (limited to 'build2/filesystem.cxx')
-rw-r--r--build2/filesystem.cxx59
1 files changed, 59 insertions, 0 deletions
diff --git a/build2/filesystem.cxx b/build2/filesystem.cxx
index 47a711f..8b4e3ec 100644
--- a/build2/filesystem.cxx
+++ b/build2/filesystem.cxx
@@ -189,4 +189,63 @@ namespace build2
fail << "unable to scan directory " << d << ": " << e << endf;
}
}
+
+ const path buildignore (".buildignore");
+
+ fs_status<mkdir_status>
+ mkdir_buildignore (const dir_path& d, uint16_t verbosity)
+ {
+ fs_status<mkdir_status> r (mkdir (d, verbosity));
+
+ // Create the .buildignore file if the directory was created (and so is
+ // empty) or the file doesn't exist.
+ //
+ path p (d / buildignore);
+ if (r || !exists (p))
+ touch (p, true /* create */, verbosity);
+
+ return r;
+ }
+
+ bool
+ empty_buildignore (const dir_path& d)
+ {
+ try
+ {
+ for (const dir_entry& de: dir_iterator (d, false /* ignore_dangling */))
+ {
+ // The .buildignore filesystem entry should be of the regular file
+ // type.
+ //
+ if (de.path () != buildignore || de.ltype () != entry_type::regular)
+ return false;
+ }
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to scan directory " << d << ": " << e;
+ }
+
+ return true;
+ }
+
+ fs_status<rmdir_status>
+ rmdir_buildignore (const dir_path& d, uint16_t verbosity)
+ {
+ // We should remove the .buildignore file only if the subsequent rmdir()
+ // will succeed. In other words if the directory stays after the function
+ // call then the .buildignore file must stay also, if present. Thus, we
+ // first check that the directory is otherwise empty and doesn't contain
+ // the working directory.
+ //
+ path p (d / buildignore);
+ if (exists (p) && empty_buildignore (d) && !work.sub (d))
+ rmfile (p, verbosity);
+
+ // Note that in case of a system error the directory is likely to stay and
+ // the .buildfile is already removed. Trying to restore it feels like an
+ // overkill here.
+ //
+ return rmdir (d, verbosity);
+ }
}