From 65ae8fab065de81a777e679528a3859c621836da Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:51:46 +0000 Subject: Fixed function return and moved cdrom stuff to lib Author: jgg Date: 1998-11-29 01:19:20 GMT Fixed function return and moved cdrom stuff to lib --- cmdline/apt-cdrom.cc | 137 ++------------------------------------------------- 1 file changed, 4 insertions(+), 133 deletions(-) diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index fc9eb5000..5a0ace8b6 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: apt-cdrom.cc,v 1.5 1998/11/28 08:39:46 jgg Exp $ +// $Id: apt-cdrom.cc,v 1.6 1998/11/29 01:19:20 jgg Exp $ /* ###################################################################### APT CDROM - Tool for handling APT's CDROM database. @@ -14,10 +14,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -25,9 +25,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -35,134 +32,6 @@ #include /*}}}*/ -// UnmountCdrom - Unmount a cdrom /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool UnmountCdrom(string Path) -{ - int Child = fork(); - if (Child < -1) - return _error->Errno("fork","Failed to fork"); - - // The child - if (Child == 0) - { - // Make all the fds /dev/null - for (int I = 0; I != 10; I++) - close(I); - for (int I = 0; I != 3; I++) - dup2(open("/dev/null",O_RDWR),I); - - const char *Args[10]; - Args[0] = "umount"; - Args[1] = Path.c_str(); - Args[2] = 0; - execvp(Args[0],(char **)Args); - exit(100); - } - - // Wait for mount - int Status = 0; - while (waitpid(Child,&Status,0) != Child) - { - if (errno == EINTR) - continue; - return _error->Errno("waitpid","Couldn't wait for subprocess"); - } - - // Check for an error code. - if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) - return false; - return true; -} - /*}}}*/ -// MountCdrom - Mount a cdrom /*{{{*/ -// --------------------------------------------------------------------- -/* We fork mount.. */ -bool MountCdrom(string Path) -{ - int Child = fork(); - if (Child < -1) - return _error->Errno("fork","Failed to fork"); - - // The child - if (Child == 0) - { - // Make all the fds /dev/null - for (int I = 0; I != 10; I++) - close(I); - for (int I = 0; I != 3; I++) - dup2(open("/dev/null",O_RDWR),I); - - const char *Args[10]; - Args[0] = "mount"; - Args[1] = Path.c_str(); - Args[2] = 0; - execvp(Args[0],(char **)Args); - exit(100); - } - - // Wait for mount - int Status = 0; - while (waitpid(Child,&Status,0) != Child) - { - if (errno == EINTR) - continue; - return _error->Errno("waitpid","Couldn't wait for subprocess"); - } - - // Check for an error code. - if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) - return false; - return true; -} - /*}}}*/ -// IdentCdrom - Generate a unique string for this CD /*{{{*/ -// --------------------------------------------------------------------- -/* We convert everything we hash into a string, this prevents byte size/order - from effecting the outcome. */ -bool IdentCdrom(string CD,string &Res) -{ - MD5Summation Hash; - - string StartDir = SafeGetCWD(); - if (chdir(CD.c_str()) != 0) - return _error->Errno("chdir","Unable to change to %s",CD.c_str()); - - DIR *D = opendir("."); - if (D == 0) - return _error->Errno("opendir","Unable to read %s",CD.c_str()); - - // Run over the directory - char S[300]; - for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D)) - { - // Skip some files.. - if (strcmp(Dir->d_name,".") == 0 || - strcmp(Dir->d_name,"..") == 0) - continue; - - sprintf(S,"%lu",Dir->d_ino); - Hash.Add(S); - Hash.Add(Dir->d_name); - }; - - chdir(StartDir.c_str()); - closedir(D); - - // Some stats from the fsys - struct statfs Buf; - if (statfs(CD.c_str(),&Buf) != 0) - return _error->Errno("statfs","Failed to stat the cdrom"); - - sprintf(S,"%u %u",Buf.f_blocks,Buf.f_bfree); - Hash.Add(S); - - Res = Hash.Result().Value(); - return true; -} - /*}}}*/ - // FindPackages - Find the package files on the CDROM /*{{{*/ // --------------------------------------------------------------------- /* We look over the cdrom for package files. This is a recursive @@ -689,6 +558,8 @@ bool CopyPackages(string CDROM,string Name,vector &List) if (NotFound + WrongSize > 10) cout << "Alot of package entires were discarded, perhaps this CD is funny?" << endl; + + return true; } /*}}}*/ -- cgit v1.2.3