summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:54:47 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:54:47 +0000
commit421c8d109932a2615b9327c8b69aad715d4b1162 (patch)
tree598bab85a1d54cda33ef75662b5287b2c47f7be0 /apt-pkg/contrib
parenteecf9bf7744f44f011234bccfc35218f80ae3526 (diff)
Bug fixes
Author: jgg Date: 1999-09-30 06:30:34 GMT Bug fixes
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/fileutl.cc41
-rw-r--r--apt-pkg/contrib/fileutl.h3
2 files changed, 42 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index a2c6ab370..ddb07532d 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.30 1999/07/26 17:46:08 jgg Exp $
+// $Id: fileutl.cc,v 1.31 1999/09/30 06:30:34 jgg Exp $
/* ######################################################################
File Utilities
@@ -150,6 +150,45 @@ string flNotFile(string File)
return string(File,0,Res);
}
/*}}}*/
+// flNoLink - If file is a symlink then deref it /*{{{*/
+// ---------------------------------------------------------------------
+/* If the name is not a link then the returned path is the input. */
+string flNoLink(string File)
+{
+ struct stat St;
+ if (lstat(File.c_str(),&St) != 0 || S_ISLNK(St.st_mode) == 0)
+ return File;
+ if (stat(File.c_str(),&St) != 0)
+ return File;
+
+ /* Loop resolving the link. There is no need to limit the number of
+ loops because the stat call above ensures that the symlink is not
+ circular */
+ char Buffer[1024];
+ string NFile = File;
+ while (1)
+ {
+ // Read the link
+ int Res;
+ if ((Res = readlink(NFile.c_str(),Buffer,sizeof(Buffer))) <= 0 ||
+ (unsigned)Res >= sizeof(Buffer))
+ return File;
+
+ // Append or replace the previous path
+ Buffer[Res] = 0;
+ if (Buffer[0] == '/')
+ NFile = Buffer;
+ else
+ NFile = flNotFile(NFile) + Buffer;
+
+ // See if we are done
+ if (lstat(NFile.c_str(),&St) != 0)
+ return File;
+ if (S_ISLNK(St.st_mode) == 0)
+ return NFile;
+ }
+}
+ /*}}}*/
// SetCloseExec - Set the close on exec flag /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index fe904acf5..7ad630ce3 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.h,v 1.21 1999/07/26 17:46:08 jgg Exp $
+// $Id: fileutl.h,v 1.22 1999/09/30 06:30:34 jgg Exp $
/* ######################################################################
File Utilities
@@ -83,5 +83,6 @@ bool ExecWait(int Pid,const char *Name,bool Reap = false);
// File string manipulators
string flNotDir(string File);
string flNotFile(string File);
+string flNoLink(string File);
#endif