diff options
author | Michael Vogt <mvo@debian.org> | 2011-03-10 11:31:34 +0100 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2011-03-10 11:31:34 +0100 |
commit | 5039a4c529d8c62bfd770fe90347a7805f31724a (patch) | |
tree | f6414e867aa5827cc94313a67546d7a79e902bad /apt-pkg | |
parent | e9ecab0f97be19326c52f2afe04fd9b44eba01ae (diff) | |
parent | c9952021ba65db0581f6053cd6d6e8bf7d563e8f (diff) |
merged the lp:~mvo/apt/mvo branch
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/cdrom.cc | 31 | ||||
-rw-r--r-- | apt-pkg/cdrom.h | 8 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 31 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.h | 1 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 9 | ||||
-rw-r--r-- | apt-pkg/deb/debindexfile.cc | 5 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 9 |
7 files changed, 88 insertions, 6 deletions
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 04ace10a6..55600fe57 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -854,6 +854,7 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/ libudev_handle = h; udev_new = (udev* (*)(void)) dlsym(h, "udev_new"); udev_enumerate_add_match_property = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_property"); + udev_enumerate_add_match_sysattr = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_sysattr"); udev_enumerate_scan_devices = (int (*)(udev_enumerate*))dlsym(h, "udev_enumerate_scan_devices"); udev_enumerate_get_list_entry = (udev_list_entry* (*)(udev_enumerate*))dlsym(h, "udev_enumerate_get_list_entry"); udev_device_new_from_syspath = (udev_device* (*)(udev*, const char*))dlsym(h, "udev_device_new_from_syspath"); @@ -867,8 +868,20 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/ return true; } /*}}}*/ + + /*{{{*/ +// compatiblity only with the old API/ABI, can be removed on the next +// ABI break +vector<CdromDevice> +pkgUdevCdromDevices::Scan() +{ + bool CdromOnly = _config->FindB("APT::cdrom::CdromOnly", true); + return ScanForRemovable(CdromOnly); +}; + /*}}}*/ + /*{{{*/ vector<CdromDevice> -pkgUdevCdromDevices::Scan() /*{{{*/ +pkgUdevCdromDevices::ScanForRemovable(bool CdromOnly) { vector<CdromDevice> cdrom_devices; struct udev_enumerate *enumerate; @@ -880,7 +893,10 @@ pkgUdevCdromDevices::Scan() /*{{{*/ udev_ctx = udev_new(); enumerate = udev_enumerate_new (udev_ctx); - udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1"); + if (CdromOnly) + udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1"); + else + udev_enumerate_add_match_sysattr(enumerate, "removable", "1"); udev_enumerate_scan_devices (enumerate); devices = udev_enumerate_get_list_entry (enumerate); @@ -892,11 +908,18 @@ pkgUdevCdromDevices::Scan() /*{{{*/ if (udevice == NULL) continue; const char* devnode = udev_device_get_devnode(udevice); - const char* mountpath = udev_device_get_property_value(udevice, "FSTAB_DIR"); + + // try fstab_dir first + string mountpath; + const char* mp = udev_device_get_property_value(udevice, "FSTAB_DIR"); + if (mp) + mountpath = string(mp); + else + mountpath = FindMountPointForDevice(devnode); // fill in the struct cdrom.DeviceName = string(devnode); - if (mountpath) { + if (mountpath != "") { cdrom.MountPath = mountpath; string s = string(mountpath); cdrom.Mounted = IsMounted(s); diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h index 14ca1d810..032fae755 100644 --- a/apt-pkg/cdrom.h +++ b/apt-pkg/cdrom.h @@ -68,7 +68,7 @@ class pkgCdrom /*{{{*/ /*}}}*/ -// class that uses libudev to find cdrom devices dynamically +// class that uses libudev to find cdrom/removable devices dynamically struct CdromDevice /*{{{*/ { string DeviceName; @@ -92,6 +92,7 @@ class pkgUdevCdromDevices /*{{{*/ struct udev_enumerate *(*udev_enumerate_new) (struct udev *udev); struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *list_entry); const char* (*udev_device_get_property_value)(struct udev_device *udev_device, const char *key); + int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value); // end libudev dlopen public: @@ -100,7 +101,12 @@ class pkgUdevCdromDevices /*{{{*/ // try to open bool Dlopen(); + + // this is the new interface + vector<CdromDevice> ScanForRemovable(bool CdromOnly); + // FIXME: compat with the old interface/API/ABI only vector<CdromDevice> Scan(); + }; /*}}}*/ diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 68b980407..83c324f54 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -15,6 +15,7 @@ #include <apt-pkg/md5.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/configuration.h> +#include <apt-pkg/strutl.h> #include <apti18n.h> @@ -234,3 +235,33 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) return true; } /*}}}*/ + +// FindMountPointForDevice - Find mountpoint for the given device /*{{{*/ +string FindMountPointForDevice(const char *devnode) +{ + char buf[255]; + char *out[10]; + int i=0; + + // this is the order that mount uses as well + const char *mount[] = { "/etc/mtab", + "/proc/mount", + NULL }; + + for (i=0; mount[i] != NULL; i++) { + if (FileExists(mount[i])) { + FILE *f=fopen(mount[i], "r"); + while ( fgets(buf, sizeof(buf), f) != NULL) { + if (strncmp(buf, devnode, strlen(devnode)) == 0) { + if(TokSplitString(' ', buf, out, 10)) + return string(out[1]); + } + } + fclose(f); + } + } + + return string(); +} + + diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h index 9d14249c5..38ed2996e 100644 --- a/apt-pkg/contrib/cdromutl.h +++ b/apt-pkg/contrib/cdromutl.h @@ -19,5 +19,6 @@ bool MountCdrom(string Path, string DeviceName=""); bool UnmountCdrom(string Path); bool IdentCdrom(string CD,string &Res,unsigned int Version = 2); bool IsMounted(string &Path); +string FindMountPointForDevice(const char *device); #endif diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 767951daf..50019872e 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -67,6 +67,15 @@ bool RunScripts(const char *Cnf) // This is the child if (Child == 0) { + if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") + { + std::cerr << "Chrooting into " + << _config->FindDir("DPkg::Chroot-Directory") + << std::endl; + if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0) + _exit(100); + } + if (chdir("/tmp/") != 0) _exit(100); diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 9961b5ae4..1e8c04033 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -66,7 +66,10 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const string SourcesURI = _config->FindDir("Dir::State::lists") + URItoFileName(IndexURI("Sources")); string SourcesURIgzip = SourcesURI + ".gz"; - if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip)) + + if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip)) + return NULL; + else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip)) SourcesURI = SourcesURIgzip; return new debSrcRecordParser(SourcesURI,this); diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 7b0955b96..eb9abe909 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -308,6 +308,15 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) SetCloseExec(STDIN_FILENO,false); SetCloseExec(STDERR_FILENO,false); + if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") + { + std::cerr << "Chrooting into " + << _config->FindDir("DPkg::Chroot-Directory") + << std::endl; + if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0) + _exit(100); + } + const char *Args[4]; Args[0] = "/bin/sh"; Args[1] = "-c"; |