summaryrefslogtreecommitdiff
path: root/sbuild/sbuild-util.cc
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2009-03-19 22:42:28 +0000
committerRoger Leigh <rleigh@debian.org>2009-03-19 22:42:28 +0000
commit5c9d4b6a9c8b1e1a1f007079659056bae7ba5190 (patch)
treea748e99297f49815cf82187e3362d63b63aced54 /sbuild/sbuild-util.cc
parentf523755ef62c43fb8bf3565dba2181af78296e8b (diff)
downloadschroot-5c9d4b6a9c8b1e1a1f007079659056bae7ba5190.tar.gz
[sbuild] sbuild-util: Add is_valid_filename
is_valid_filename is a new function to check that a filename is valid to open (i.e. is not a backup file, a dpkg configuration file backup etc.) using the run-parts(8) matching rules. This has been moved from sbuild::run_parts::check_filename.
Diffstat (limited to 'sbuild/sbuild-util.cc')
-rw-r--r--sbuild/sbuild-util.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/sbuild/sbuild-util.cc b/sbuild/sbuild-util.cc
index 4d3cd874..1cfa6806 100644
--- a/sbuild/sbuild-util.cc
+++ b/sbuild/sbuild-util.cc
@@ -158,6 +158,36 @@ sbuild::is_absname (std::string const& name)
return true;
}
+bool
+sbuild::is_valid_filename (std::string const& name,
+ bool lsb_mode)
+{
+ bool match = false;
+
+ if (lsb_mode)
+ {
+ static regex lanana_namespace("^[a-z0-9]+$");
+ static regex lsb_namespace("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
+ static regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$");
+ static regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp)$");
+
+ if ((regex_search(name, lanana_namespace) ||
+ regex_search(name, lsb_namespace) ||
+ regex_search(name, debian_cron_namespace)) &&
+ !regex_search(name, debian_dpkg_conffile_cruft))
+ match = true;
+ }
+ else
+ {
+ static regex traditional_namespace("^[a-zA-Z0-9_-]$");
+ if (regex_search(name, traditional_namespace))
+ match = true;
+ }
+
+ return match;
+}
+
+
std::string
sbuild::string_list_to_string (sbuild::string_list const& list,
std::string const& separator)