X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/6c9079759285e073024f7e3193c990ede2a17cef..6627bdccce46a9acdae09d37e6e1444a5f7384e1:/apt-pkg/contrib/cdromutl.cc?ds=sidebyside diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index c24970553..ab170ec5a 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: cdromutl.cc,v 1.3 1999/04/03 01:05:24 jgg Exp $ +// $Id: cdromutl.cc,v 1.12 2001/02/20 07:03:17 jgg Exp $ /* ###################################################################### CDROM Utilities - Some functions to manipulate CDROM mounts. @@ -19,9 +19,11 @@ #include #include +#include + #include #include -#include +#include #include #include #include @@ -50,7 +52,7 @@ bool IsMounted(string &Path) struct stat Buf,Buf2; if (stat(Path.c_str(),&Buf) != 0 || stat((Path + "../").c_str(),&Buf2) != 0) - return _error->Errno("stat","Unable to stat the mount point %s",Path.c_str()); + return _error->Errno("stat",_("Unable to stat the mount point %s"),Path.c_str()); if (Buf.st_dev == Buf2.st_dev) return false; @@ -66,16 +68,12 @@ bool UnmountCdrom(string Path) if (IsMounted(Path) == false) return true; - int Child = fork(); - if (Child < -1) - return _error->Errno("fork","Failed to fork"); + int Child = ExecFork(); // 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); @@ -97,18 +95,7 @@ bool UnmountCdrom(string Path) } // 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; + return ExecWait(Child,"umount",true); } /*}}}*/ // MountCdrom - Mount a cdrom /*{{{*/ @@ -119,16 +106,12 @@ bool MountCdrom(string Path) if (IsMounted(Path) == true) return true; - int Child = fork(); - if (Child < -1) - return _error->Errno("fork","Failed to fork"); + int Child = ExecFork(); // 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); @@ -150,35 +133,24 @@ bool MountCdrom(string Path) } // 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; + return ExecWait(Child,"mount",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) +bool IdentCdrom(string CD,string &Res,unsigned int Version) { MD5Summation Hash; string StartDir = SafeGetCWD(); if (chdir(CD.c_str()) != 0) - return _error->Errno("chdir","Unable to change to %s",CD.c_str()); + 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()); + return _error->Errno("opendir",_("Unable to read %s"),CD.c_str()); /* Run over the directory, we assume that the reader order will never change as the media is read-only. In theory if the kernel did @@ -190,8 +162,19 @@ bool IdentCdrom(string CD,string &Res) if (strcmp(Dir->d_name,".") == 0 || strcmp(Dir->d_name,"..") == 0) continue; - - sprintf(S,"%lu",Dir->d_ino); + + if (Version <= 1) + { + sprintf(S,"%lu",(unsigned long)Dir->d_ino); + } + else + { + struct stat Buf; + if (stat(Dir->d_name,&Buf) != 0) + continue; + sprintf(S,"%lu",(unsigned long)Buf.st_mtime); + } + Hash.Add(S); Hash.Add(Dir->d_name); }; @@ -200,16 +183,22 @@ bool IdentCdrom(string CD,string &Res) 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"); - - // We use a kilobyte block size to advoid overflow - sprintf(S,"%u %u",Buf.f_blocks*(Buf.f_bsize/1024), - Buf.f_bfree*(Buf.f_bsize/1024)); - Hash.Add(S); + if (_config->FindB("Debug::identcdrom",false) == false) + { + struct statvfs Buf; + if (statvfs(CD.c_str(),&Buf) != 0) + return _error->Errno("statfs",_("Failed to stat the cdrom")); + + // We use a kilobyte block size to advoid overflow + sprintf(S,"%lu %lu",(long)(Buf.f_blocks*(Buf.f_bsize/1024)), + (long)(Buf.f_bfree*(Buf.f_bsize/1024))); + Hash.Add(S); + sprintf(S,"-%u",Version); + } + else + sprintf(S,"-%u.debug",Version); - Res = Hash.Result().Value(); + Res = Hash.Result().Value() + S; return true; } /*}}}*/