summaryrefslogtreecommitdiffstats
path: root/patches/busybox-1.9.1/generic/busybox-1.9.1-patch_permissions.patch
blob: 9ad8e6550271e04791ec19f32f367d28d9042b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Subject: busybox 1.9.1 fixes
From: http://busybox.net/downloads/fixes-1.9.1

---
 editors/patch.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Index: busybox-1.9.1/editors/patch.c
===================================================================
--- busybox-1.9.1.orig/editors/patch.c
+++ busybox-1.9.1/editors/patch.c
@@ -71,12 +71,6 @@ static char *extract_filename(char *line
 	return xstrdup(filename_start_ptr);
 }
 
-static int file_doesnt_exist(const char *filename)
-{
-	struct stat statbuf;
-	return stat(filename, &statbuf);
-}
-
 int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int patch_main(int argc, char **argv)
 {
@@ -84,7 +78,8 @@ int patch_main(int argc, char **argv)
 	char *patch_line;
 	int ret;
 	FILE *patch_file = NULL;
-
+	struct stat saved_stat;
+	
 	{
 		char *p, *i;
 		ret = getopt32(argv, "p:i:", &p, &i);
@@ -134,8 +129,9 @@ int patch_main(int argc, char **argv)
 		}
 		new_filename = extract_filename(patch_line, patch_level);
 		free(patch_line);
-
-		if (file_doesnt_exist(new_filename)) {
+		
+		/* Get access rights from the file to be patched, -1 file does not exist */
+		if (stat(new_filename, &saved_stat)) {
 			char *line_ptr;
 			/* Create leading directories */
 			line_ptr = strrchr(new_filename, '/');
@@ -155,9 +151,10 @@ int patch_main(int argc, char **argv)
 						backup_filename);
 			}
 			dst_stream = xfopen(new_filename, "w");
+			fchmod(fileno(dst_stream), saved_stat.st_mode);
 		}
 
-		if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) {
+		if ((backup_filename == NULL) || stat(original_filename, &saved_stat)) {
 			src_stream = NULL;
 		} else {
 			if (strcmp(original_filename, new_filename) == 0) {