Home | History | Annotate | Download | only in applypatch

Lines Matching defs:file

5  * you may not use this file except in compliance with the License.
33 static int LoadPartitionContents(const char* filename, FileContents* file);
47 // Read a file into memory; optionally (retouch_flag == RETOUCH_DO_MASK) mask
49 // don't fail due to randomization); store the file contents and associated
50 // metadata in *file.
53 int LoadFileContents(const char* filename, FileContents* file,
55 file->data = NULL;
61 return LoadPartitionContents(filename, file);
64 if (stat(filename, &file->st) != 0) {
69 file->size = file->st.st_size;
70 file->data = malloc(file->size);
72 FILE* f = fopen(filename, "rb");
75 free(file->data);
76 file->data = NULL;
80 ssize_t bytes_read = fread(file->data, 1, file->size, f);
81 if (bytes_read != file->size) {
83 filename, (long)bytes_read, (long)file->size);
84 free(file->data);
85 file->data = NULL;
92 // within a file, this means the file is assumed "corrupt" for simplicity.
95 if (retouch_mask_data(file->data, file->size,
98 free(file->data);
99 file->data = NULL;
104 SHA_hash(file->data, file->size, file->sha1);
135 // "end-of-file" marker), so the caller must specify the possible
140 static int LoadPartitionContents(const char* filename, FileContents* file) {
191 FILE* dev = NULL;
229 file->data = malloc(size[index[pairs-1]]);
230 char* p = (char*)file->data;
231 file->size = 0; // # bytes read so far
237 size_t next = size[index[i]] - file->size;
252 free(file->data);
253 file->data = NULL;
257 file->size += read;
269 free(file->data);
270 file->data = NULL;
301 free(file->data);
302 file->data = NULL;
308 file->sha1[i] = sha_final[i];
312 file->st.st_mode = 0644;
313 file->st.st_uid = 0;
314 file->st.st_gid = 0;
327 int SaveFileContents(const char* filename, const FileContents* file) {
335 ssize_t bytes_written = FileSink(file->data, file->size, &fd);
336 if (bytes_written != file->size) {
338 filename, (long)bytes_written, (long)file->size,
346 if (chmod(filename, file->st.st_mode) != 0) {
350 if (chown(filename, file->st.st_uid, file->st.st_gid) != 0) {
570 // Returns 0 if the contents of the file (argv[2]) or the cached file
575 FileContents file;
576 file.data = NULL;
582 if (LoadFileContents(filename, &file, RETOUCH_DO_MASK) != 0 ||
584 FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0)) {
585 printf("file \"%s\" doesn't have any of expected "
588 free(file.data);
589 file.data = NULL;
591 // If the source file is missing or corrupted, it might be because
593 // should have been made in CACHE_TEMP_SOURCE. If that file
597 if (LoadFileContents(CACHE_TEMP_SOURCE, &file, RETOUCH_DO_MASK) != 0) {
598 printf("failed to load cache file\n");
602 if (FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0) {
604 free(file.data);
609 free(file.data);
679 // (the original file is not touched until we have the desired
689 // new file (the type of patch is automatically detected from the
690 // blob daat). If that new file has sha1 hash <target_sha1_str>,
732 // We try to load the target file into the source_file object.
736 // The early-exit case: the patch was already applied, this file
749 // Need to load the source file: either we failed to load the
750 // target file, or we did but it's different from the source file.
768 printf("source file is bad; trying copy\n");
773 printf("failed to read copy file\n");
785 printf("copy file doesn't match source SHA-1s either\n");
833 // file?
841 // space to hold the file.
850 printf("failed to back up source file\n");
874 // copy the source file to cache, then delete it from the original
893 printf("failed to back up source file\n");
936 // We write the decoded output to "<tgt-file>.patch".
943 printf("failed to open output file %s: %s\n",
967 printf("Unknown patch file format\n");
1003 // Copy the temp file to the partition.
1010 // Give the .patch file the same owner, group, and mode of the
1011 // original source file.
1022 // Finally, rename the .patch file to replace the target file.