summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/configuration.cc10
-rw-r--r--apt-pkg/contrib/fileutl.cc19
-rw-r--r--apt-pkg/contrib/fileutl.h2
3 files changed, 22 insertions, 9 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 3cb7fde06..9007bf9ec 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -225,15 +225,7 @@ string Configuration::FindFile(const char *Name,const char *Default) const
}
result.append(val);
}
-
- // do some normalisation by removing // and /./ from the path
- size_t found = string::npos;
- while ((found = result.find("/./")) != string::npos)
- result.replace(found, 3, "/");
- while ((found = result.find("//")) != string::npos)
- result.replace(found, 2, "/");
-
- return result;
+ return flNormalize(result);
}
/*}}}*/
// Configuration::FindDir - Find a directory name /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index e410f52d6..fa0930dff 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -694,6 +694,25 @@ string flAbsPath(string File)
return AbsPath;
}
/*}}}*/
+std::string flNormalize(std::string file) /*{{{*/
+{
+ if (file.empty())
+ return file;
+ // do some normalisation by removing // and /./ from the path
+ size_t found = string::npos;
+ while ((found = file.find("/./")) != string::npos)
+ file.replace(found, 3, "/");
+ while ((found = file.find("//")) != string::npos)
+ file.replace(found, 2, "/");
+
+ if (APT::String::Startswith(file, "/dev/null"))
+ {
+ file.erase(strlen("/dev/null"));
+ return file;
+ }
+ return file;
+}
+ /*}}}*/
// SetCloseExec - Set the close on exec flag /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index f33f7804b..c13613171 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -234,6 +234,8 @@ std::string flCombine(std::string Dir,std::string File);
/** \brief Takes a file path and returns the absolute path
*/
std::string flAbsPath(std::string File);
+/** \brief removes superfluous /./ and // from path */
+APT_HIDDEN std::string flNormalize(std::string file);
// simple c++ glob
std::vector<std::string> Glob(std::string const &pattern, int flags=0);