@@ -762,93 +762,6 @@ Value* PackageExtractDirFn(const char* name, State* state,
762762 return StringValue (success ? " t" : " " );
763763}
764764
765- // package_extract_file(package_file[, dest_file])
766- // Extracts a single package_file from the update package and writes it to dest_file,
767- // overwriting existing files if necessary. Without the dest_file argument, returns the
768- // contents of the package file as a binary blob.
769- Value* PackageExtractFileFn (const char * name, State* state,
770- const std::vector<std::unique_ptr<Expr>>& argv) {
771- if (argv.size () < 1 || argv.size () > 2 ) {
772- return ErrorAbort (state, kArgsParsingFailure , " %s() expects 1 or 2 args, got %zu" , name,
773- argv.size ());
774- }
775-
776- if (argv.size () == 2 ) {
777- // The two-argument version extracts to a file.
778-
779- std::vector<std::string> args;
780- if (!ReadArgs (state, argv, &args)) {
781- return ErrorAbort (state, kArgsParsingFailure , " %s() Failed to parse %zu args" , name,
782- argv.size ());
783- }
784- const std::string& zip_path = args[0 ];
785- const std::string& dest_path = args[1 ];
786-
787- ZipArchiveHandle za = static_cast <UpdaterInfo*>(state->cookie )->package_zip ;
788- ZipString zip_string_path (zip_path.c_str ());
789- ZipEntry entry;
790- if (FindEntry (za, zip_string_path, &entry) != 0 ) {
791- LOG (ERROR ) << name << " : no " << zip_path << " in package" ;
792- return StringValue (" " );
793- }
794-
795- unique_fd fd (TEMP_FAILURE_RETRY (
796- ota_open (dest_path.c_str (), O_WRONLY | O_CREAT | O_TRUNC , S_IRUSR | S_IWUSR )));
797- if (fd == -1 ) {
798- PLOG (ERROR ) << name << " : can't open " << dest_path << " for write" ;
799- return StringValue (" " );
800- }
801-
802- bool success = true ;
803- int32_t ret = ExtractEntryToFile (za, &entry, fd);
804- if (ret != 0 ) {
805- LOG (ERROR ) << name << " : Failed to extract entry \" " << zip_path << " \" ("
806- << entry.uncompressed_length << " bytes) to \" " << dest_path
807- << " \" : " << ErrorCodeString (ret);
808- success = false ;
809- }
810- if (ota_fsync (fd) == -1 ) {
811- PLOG (ERROR ) << " fsync of \" " << dest_path << " \" failed" ;
812- success = false ;
813- }
814- if (ota_close (fd) == -1 ) {
815- PLOG (ERROR ) << " close of \" " << dest_path << " \" failed" ;
816- success = false ;
817- }
818-
819- return StringValue (success ? " t" : " " );
820- } else {
821- // The one-argument version returns the contents of the file as the result.
822-
823- std::vector<std::string> args;
824- if (!ReadArgs (state, argv, &args)) {
825- return ErrorAbort (state, kArgsParsingFailure , " %s() Failed to parse %zu args" , name,
826- argv.size ());
827- }
828- const std::string& zip_path = args[0 ];
829-
830- ZipArchiveHandle za = static_cast <UpdaterInfo*>(state->cookie )->package_zip ;
831- ZipString zip_string_path (zip_path.c_str ());
832- ZipEntry entry;
833- if (FindEntry (za, zip_string_path, &entry) != 0 ) {
834- return ErrorAbort (state, kPackageExtractFileFailure , " %s(): no %s in package" , name,
835- zip_path.c_str ());
836- }
837-
838- std::string buffer;
839- buffer.resize (entry.uncompressed_length );
840-
841- int32_t ret = ExtractToMemory (za, &entry, reinterpret_cast <uint8_t *>(&buffer[0 ]), buffer.size ());
842- if (ret != 0 ) {
843- return ErrorAbort (state, kPackageExtractFileFailure ,
844- " %s: Failed to extract entry \" %s\" (%zu bytes) to memory: %s" , name,
845- zip_path.c_str (), buffer.size (), ErrorCodeString (ret));
846- }
847-
848- return new Value (VAL_BLOB , buffer);
849- }
850- }
851-
852765// symlink(target, [src1, src2, ...])
853766// Creates all sources as symlinks to target. It unlinks any previously existing src1, src2, etc
854767// before creating symlinks.
0 commit comments