Home | History | Annotate | Download | only in applypatch

Lines Matching defs:file

5  * you may not use this file except in compliance with the License.
34 static int LoadPartitionContents(const char* filename, FileContents* file);
48 // Read a file into memory; store the file contents and associated
49 // metadata in *file.
52 int LoadFileContents(const char* filename, FileContents* file) {
53 file->data = NULL;
59 return LoadPartitionContents(filename, file);
62 if (stat(filename, &file->st) != 0) {
67 file->size = file->st.st_size;
68 file->data = malloc(file->size);
70 FILE* f = fopen(filename, "rb");
73 free(file->data);
74 file->data = NULL;
78 ssize_t bytes_read = fread(file->data, 1, file->size, f);
79 if (bytes_read != file->size) {
81 filename, (long)bytes_read, (long)file->size);
82 free(file->data);
83 file->data = NULL;
88 SHA_hash(file->data, file->size, file->sha1);
119 // "end-of-file" marker), so the caller must specify the possible
124 static int LoadPartitionContents(const char* filename, FileContents* file) {
175 FILE* dev = NULL;
213 file->data = malloc(size[index[pairs-1]]);
214 char* p = (char*)file->data;
215 file->size = 0; // # bytes read so far
221 size_t next = size[index[i]] - file->size;
236 free(file->data);
237 file->data = NULL;
241 file->size += read;
253 free(file->data);
254 file->data = NULL;
285 free(file->data);
286 file->data = NULL;
292 file->sha1[i] = sha_final[i];
296 file->st.st_mode = 0644;
297 file->st.st_uid = 0;
298 file->st.st_gid = 0;
311 int SaveFileContents(const char* filename, const FileContents* file) {
319 ssize_t bytes_written = FileSink(file->data, file->size, &fd);
320 if (bytes_written != file->size) {
322 filename, (long)bytes_written, (long)file->size,
336 if (chmod(filename, file->st.st_mode) != 0) {
340 if (chown(filename, file->st.st_uid, file->st.st_gid) != 0) {
578 // Returns 0 if the contents of the file (argv[2]) or the cached file
583 FileContents file;
584 file.data = NULL;
590 if (LoadFileContents(filename, &file) != 0 ||
592 FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0)) {
593 printf("file \"%s\" doesn't have any of expected "
596 free(file.data);
597 file.data = NULL;
599 // If the source file is missing or corrupted, it might be because
601 // should have been made in CACHE_TEMP_SOURCE. If that file
605 if (LoadFileContents(CACHE_TEMP_SOURCE, &file) != 0) {
606 printf("failed to load cache file\n");
610 if (FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0) {
612 free(file.data);
617 free(file.data);
687 // (the original file is not touched until we have the desired
697 // new file (the type of patch is automatically detected from the
698 // blob daat). If that new file has sha1 hash <target_sha1_str>,
740 // We try to load the target file into the source_file object.
743 // The early-exit case: the patch was already applied, this file
756 // Need to load the source file: either we failed to load the
757 // target file, or we did but it's different from the source file.
774 printf("source file is bad; trying copy\n");
778 printf("failed to read copy file\n");
790 printf("copy file doesn't match source SHA-1s either\n");
838 // file?
846 // space to hold the file.
855 printf("failed to back up source file\n");
879 // copy the source file to cache, then delete it from the original
898 printf("failed to back up source file\n");
941 // We write the decoded output to "<tgt-file>.patch".
949 printf("failed to open output file %s: %s\n",
973 printf("Unknown patch file format\n");
979 printf("failed to fsync file \"%s\" (%s)\n", outname, strerror(errno));
983 printf("failed to close file \"%s\" (%s)\n", outname, strerror(errno));
1015 // Copy the temp file to the partition.
1022 // Give the .patch file the same owner, group, and mode of the
1023 // original source file.
1034 // Finally, rename the .patch file to replace the target file.