Sfoglia il codice sorgente

Merge branch 'feature/abspath' into feature/apt-install-deb

Conflicts:
	test/libapt/fileutl_test.cc
Michael Vogt 12 anni fa
parent
commit
8e0002ac42
3 ha cambiato i file con 27 aggiunte e 1 eliminazioni
  1. 16 0
      apt-pkg/contrib/fileutl.cc
  2. 4 0
      apt-pkg/contrib/fileutl.h
  3. 7 1
      test/libapt/fileutl_test.cc

+ 16 - 0
apt-pkg/contrib/fileutl.cc

@@ -659,6 +659,22 @@ string flCombine(string Dir,string File)
    return Dir + '/' + File;
    return Dir + '/' + File;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// flAbsPath - Return the absolute path of the filename			/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string flAbsPath(string File)
+{
+   char *p = realpath(File.c_str(), NULL);
+   if (p == NULL)
+   {
+      _error->Errno("realpath", "flAbsPath failed");
+      return "";
+   }
+   std::string AbsPath(p);
+   free(p);
+   return AbsPath;
+}
+									/*}}}*/
 // SetCloseExec - Set the close on exec flag				/*{{{*/
 // SetCloseExec - Set the close on exec flag				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */

+ 4 - 0
apt-pkg/contrib/fileutl.h

@@ -200,6 +200,10 @@ std::string flNoLink(std::string File);
 std::string flExtension(std::string File);
 std::string flExtension(std::string File);
 std::string flCombine(std::string Dir,std::string File);
 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);
+
 // simple c++ glob
 // simple c++ glob
 std::vector<std::string> Glob(std::string const &pattern, int flags=0);
 std::vector<std::string> Glob(std::string const &pattern, int flags=0);
 
 

+ 7 - 1
test/libapt/fileutl_test.cc

@@ -224,7 +224,6 @@ TEST(FileUtlTest, GetTempDir)
    if (old_tmpdir.empty() == false)
    if (old_tmpdir.empty() == false)
       setenv("TMPDIR", old_tmpdir.c_str(), 1);
       setenv("TMPDIR", old_tmpdir.c_str(), 1);
 }
 }
-
 TEST(FileUtlTest, Popen)
 TEST(FileUtlTest, Popen)
 {
 {
    FileFd Fd;
    FileFd Fd;
@@ -272,3 +271,10 @@ TEST(FileUtlTest, Popen)
    Fd.Close();
    Fd.Close();
    ExecWait(Child, "PopenWrite");
    ExecWait(Child, "PopenWrite");
 }
 }
+TEST(FileUtlTest, flAbsPath)
+{
+   int res = chdir("/bin/");
+   EXPECT_EQ(res, 0);
+   std::string p = flAbsPath("ls");
+   EXPECT_EQ(p, "/bin/ls");
+}