]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/bzip2-1.0.2-chmod.patch
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[ipfire-2.x.git] / src / patches / bzip2-1.0.2-chmod.patch
1 --- bzip2-1.0.2/bzip2.c.nochmod 2005-05-10 16:19:45.000000000 +0200
2 +++ bzip2-1.0.2/bzip2.c 2005-05-10 16:22:00.000000000 +0200
3 @@ -312,6 +312,7 @@
4
5 static void copyFileName ( Char*, Char* );
6 static void* myMalloc ( Int32 );
7 +static int applySavedFileAttrToOutputFile ( int fd );
8
9
10
11 @@ -457,6 +458,10 @@
12 ret = fflush ( zStream );
13 if (ret == EOF) goto errhandler_io;
14 if (zStream != stdout) {
15 + int fd = fileno ( zStream );
16 + if (fd < 0) goto errhandler_io;
17 + ret = applySavedFileAttrToOutputFile ( fd );
18 + if (ret != 0) goto errhandler_io;
19 ret = fclose ( zStream );
20 outputHandleJustInCase = NULL;
21 if (ret == EOF) goto errhandler_io;
22 @@ -567,6 +572,12 @@
23
24 closeok:
25 if (ferror(zStream)) goto errhandler_io;
26 + if ( stream != stdout) {
27 + int fd = fileno ( stream );
28 + if (fd < 0) goto errhandler_io;
29 + ret = applySavedFileAttrToOutputFile ( fd );
30 + if (ret != 0) goto errhandler_io;
31 + }
32 ret = fclose ( zStream );
33 if (ret == EOF) goto errhandler_io;
34
35 @@ -1125,7 +1136,7 @@
36
37
38 static
39 -void applySavedMetaInfoToOutputFile ( Char *dstName )
40 +void applySavedTimeInfoToOutputFile ( Char *dstName )
41 {
42 # if BZ_UNIX
43 IntNative retVal;
44 @@ -1134,16 +1145,26 @@
45 uTimBuf.actime = fileMetaInfo.st_atime;
46 uTimBuf.modtime = fileMetaInfo.st_mtime;
47
48 - retVal = chmod ( dstName, fileMetaInfo.st_mode );
49 - ERROR_IF_NOT_ZERO ( retVal );
50 -
51 retVal = utime ( dstName, &uTimBuf );
52 ERROR_IF_NOT_ZERO ( retVal );
53 +# endif
54 +}
55 +
56 +static
57 +int applySavedFileAttrToOutputFile ( int fd )
58 +{
59 +# if BZ_UNIX
60 + IntNative retVal;
61 +
62 + retVal = fchmod ( fd, fileMetaInfo.st_mode );
63 + if (retVal != 0)
64 + return retVal;
65
66 - retVal = chown ( dstName, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
67 + (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
68 /* chown() will in many cases return with EPERM, which can
69 be safely ignored.
70 */
71 + return 0;
72 # endif
73 }
74
75 @@ -1366,7 +1387,7 @@
76
77 /*--- If there was an I/O error, we won't get here. ---*/
78 if ( srcMode == SM_F2F ) {
79 - applySavedMetaInfoToOutputFile ( outName );
80 + applySavedTimeInfoToOutputFile ( outName );
81 deleteOutputOnInterrupt = False;
82 if ( !keepInputFiles ) {
83 IntNative retVal = remove ( inName );
84 @@ -1544,7 +1565,7 @@
85 /*--- If there was an I/O error, we won't get here. ---*/
86 if ( magicNumberOK ) {
87 if ( srcMode == SM_F2F ) {
88 - applySavedMetaInfoToOutputFile ( outName );
89 + applySavedTimeInfoToOutputFile ( outName );
90 deleteOutputOnInterrupt = False;
91 if ( !keepInputFiles ) {
92 IntNative retVal = remove ( inName );