1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dirstream.cc,v 1.3.2.1 2004/01/16 18:58:50 mdz Exp $
4 /* ######################################################################
8 This class provides a simple basic extractor that can be used for
11 ##################################################################### */
13 // Include Files /*{{{*/
14 #include <apt-pkg/dirstream.h>
15 #include <apt-pkg/error.h>
19 #include <sys/types.h>
26 // DirStream::DoItem - Process an item /*{{{*/
27 // ---------------------------------------------------------------------
28 /* This is a very simple extractor, it does not deal with things like
29 overwriting directories with files and so on. */
30 bool pkgDirStream::DoItem(Item
&Itm
,int &Fd
)
36 /* Open the output file, NDELAY is used to prevent this from
37 blowing up on device special files.. */
38 int iFd
= open(Itm
.Name
,O_NDELAY
|O_WRONLY
|O_CREAT
|O_TRUNC
|O_APPEND
,
41 return _error
->Errno("open",_("Failed to write file %s"),
44 // fchmod deals with umask and fchown sets the ownership
45 if (fchmod(iFd
,Itm
.Mode
) != 0)
46 return _error
->Errno("fchmod",_("Failed to write file %s"),
48 if (fchown(iFd
,Itm
.UID
,Itm
.GID
) != 0 && errno
!= EPERM
)
49 return _error
->Errno("fchown",_("Failed to write file %s"),
56 case Item::SymbolicLink
:
57 case Item::CharDevice
:
58 case Item::BlockDevice
:
62 // check if the dir is already there, if so return true
63 if (stat(Itm
.Name
,&Buf
) == 0)
65 if(S_ISDIR(Buf
.st_mode
))
67 // something else is there already, return false
70 // nothing here, create the dir
71 if(mkdir(Itm
.Name
,Itm
.Mode
) < 0)
83 // DirStream::FinishedFile - Finished processing a file /*{{{*/
84 // ---------------------------------------------------------------------
86 bool pkgDirStream::FinishedFile(Item
&Itm
,int Fd
)
92 return _error
->Errno("close",_("Failed to close file %s"),Itm
.Name
);
94 /* Set the modification times. The only way it can fail is if someone
95 has futzed with our file, which is intolerable :> */
97 Time
.actime
= Itm
.MTime
;
98 Time
.modtime
= Itm
.MTime
;
99 if (utime(Itm
.Name
,&Time
) != 0)
100 _error
->Errno("utime",_("Failed to close file %s"),Itm
.Name
);
105 // DirStream::Fail - Failed processing a file /*{{{*/
106 // ---------------------------------------------------------------------
108 bool pkgDirStream::Fail(Item
&Itm
,int Fd
)