]>
git.saurik.com Git - apt.git/blob - apt-inst/dirstream.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dirstream.cc,v 1.2 2001/02/20 07:03:16 jgg Exp $
4 /* ######################################################################
8 This class provides a simple basic extractor that can be used for
11 ##################################################################### */
13 // Include Files /*{{{*/
15 #pragma implementation "apt-pkg/dirstream.h"
18 #include <apt-pkg/dirstream.h>
19 #include <apt-pkg/error.h>
23 #include <sys/types.h>
29 // DirStream::DoItem - Process an item /*{{{*/
30 // ---------------------------------------------------------------------
31 /* This is a very simple extractor, it does not deal with things like
32 overwriting directories with files and so on. */
33 bool pkgDirStream::DoItem(Item
&Itm
,int &Fd
)
39 /* Open the output file, NDELAY is used to prevent this from
40 blowing up on device special files.. */
41 int iFd
= open(Itm
.Name
,O_NDELAY
|O_WRONLY
|O_CREAT
|O_TRUNC
|O_APPEND
,
44 return _error
->Errno("open","Failed write file %s",
47 // fchmod deals with umask and fchown sets the ownership
48 if (fchmod(iFd
,Itm
.Mode
) != 0)
49 return _error
->Errno("fchmod","Failed write file %s",
51 if (fchown(iFd
,Itm
.UID
,Itm
.GID
) != 0 && errno
!= EPERM
)
52 return _error
->Errno("fchown","Failed write file %s",
59 case Item::SymbolicLink
:
60 case Item::CharDevice
:
61 case Item::BlockDevice
:
70 // DirStream::FinishedFile - Finished processing a file /*{{{*/
71 // ---------------------------------------------------------------------
73 bool pkgDirStream::FinishedFile(Item
&Itm
,int Fd
)
79 return _error
->Errno("close","Failed to close file %s",Itm
.Name
);
81 /* Set the modification times. The only way it can fail is if someone
82 has futzed with our file, which is intolerable :> */
84 Time
.actime
= Itm
.MTime
;
85 Time
.modtime
= Itm
.MTime
;
86 if (utime(Itm
.Name
,&Time
) != 0)
87 _error
->Errno("utime","Failed to close file %s",Itm
.Name
);
92 // DirStream::Fail - Failed processing a file /*{{{*/
93 // ---------------------------------------------------------------------
95 bool pkgDirStream::Fail(Item
&Itm
,int Fd
)