diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-18 01:38:04 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-18 01:38:04 +0000 |
| commit | 2a7a4513918fef3bbf3d665ea0871dfc555d6692 (patch) | |
| tree | e8eee137cdcc83d1aadcffffe81c7f476117abf9 | |
| parent | d7e6af2dda0abdd7a0411af46314724bd5f88549 (diff) | |
| download | busybox-w32-2a7a4513918fef3bbf3d665ea0871dfc555d6692.tar.gz busybox-w32-2a7a4513918fef3bbf3d665ea0871dfc555d6692.tar.bz2 busybox-w32-2a7a4513918fef3bbf3d665ea0871dfc555d6692.zip | |
patch: don't trash permissions of patched file
| -rw-r--r-- | editors/patch.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/editors/patch.c b/editors/patch.c index ff1a01d2e..9a678e162 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
| @@ -71,12 +71,6 @@ static char *extract_filename(char *line, int patch_level) | |||
| 71 | return xstrdup(filename_start_ptr); | 71 | return xstrdup(filename_start_ptr); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | static int file_doesnt_exist(const char *filename) | ||
| 75 | { | ||
| 76 | struct stat statbuf; | ||
| 77 | return stat(filename, &statbuf); | ||
| 78 | } | ||
| 79 | |||
| 80 | int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 74 | int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 81 | int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | 75 | int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) |
| 82 | { | 76 | { |
| @@ -84,7 +78,8 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 84 | char *patch_line; | 78 | char *patch_line; |
| 85 | int ret; | 79 | int ret; |
| 86 | FILE *patch_file = NULL; | 80 | FILE *patch_file = NULL; |
| 87 | 81 | struct stat saved_stat; | |
| 82 | |||
| 88 | { | 83 | { |
| 89 | char *p, *i; | 84 | char *p, *i; |
| 90 | ret = getopt32(argv, "p:i:", &p, &i); | 85 | ret = getopt32(argv, "p:i:", &p, &i); |
| @@ -134,8 +129,9 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 134 | } | 129 | } |
| 135 | new_filename = extract_filename(patch_line, patch_level); | 130 | new_filename = extract_filename(patch_line, patch_level); |
| 136 | free(patch_line); | 131 | free(patch_line); |
| 137 | 132 | ||
| 138 | if (file_doesnt_exist(new_filename)) { | 133 | /* Get access rights from the file to be patched, -1 file does not exist */ |
| 134 | if (stat(new_filename, &saved_stat)) { | ||
| 139 | char *line_ptr; | 135 | char *line_ptr; |
| 140 | /* Create leading directories */ | 136 | /* Create leading directories */ |
| 141 | line_ptr = strrchr(new_filename, '/'); | 137 | line_ptr = strrchr(new_filename, '/'); |
| @@ -152,9 +148,10 @@ int patch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 152 | strcat(backup_filename, ".orig"); | 148 | strcat(backup_filename, ".orig"); |
| 153 | xrename(new_filename, backup_filename); | 149 | xrename(new_filename, backup_filename); |
| 154 | dst_stream = xfopen(new_filename, "w"); | 150 | dst_stream = xfopen(new_filename, "w"); |
| 151 | fchmod(fileno(dst_stream), saved_stat.st_mode); | ||
| 155 | } | 152 | } |
| 156 | 153 | ||
| 157 | if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) { | 154 | if ((backup_filename == NULL) || stat(original_filename, &saved_stat)) { |
| 158 | src_stream = NULL; | 155 | src_stream = NULL; |
| 159 | } else { | 156 | } else { |
| 160 | if (strcmp(original_filename, new_filename) == 0) { | 157 | if (strcmp(original_filename, new_filename) == 0) { |
