Chromium Code Reviews| Index: courgette/courgette_tool.cc |
| =================================================================== |
| --- courgette/courgette_tool.cc (revision 75361) |
| +++ courgette/courgette_tool.cc (working copy) |
| @@ -52,7 +52,11 @@ |
| #else |
| FilePath file_path(WideToASCII(file_name)); |
| #endif |
| + int64 file_size = 0; |
| + if (!file_util::GetFileSize(file_path, &file_size)) |
| + Problem("Can't read %s file.", kind); |
| std::string buffer; |
| + buffer.reserve(static_cast<size_t>(file_size)); |
| if (!file_util::ReadFileToString(file_path, &buffer)) |
| Problem("Can't read %s file.", kind); |
| return buffer; |
| @@ -285,20 +289,39 @@ |
| void ApplyEnsemblePatch(const std::wstring& old_file, |
| const std::wstring& patch_file, |
| const std::wstring& new_file) { |
| + // We do things a little differently here in order to call the same Courgette |
| + // entry point as the installer. That entry point point takes file names and |
| + // returns an status code but does not output any diagnostics. |
| +#if defined(OS_WIN) |
| + FilePath old_path(old_file); |
| + FilePath patch_path(patch_file); |
| + FilePath new_path(new_file); |
| +#else |
| + FilePath old_path(WideToASCII(old_file)); |
| + FilePath patch_path(WideToASCII(patch_file)); |
| + FilePath new_path(WideToASCII(new_file)); |
| +#endif |
| + |
| + courgette::Status status = |
| + courgette::ApplyEnsemblePatch(old_path.value().c_str(), |
|
tommi (sloooow) - chröme
2011/02/23 06:35:59
would it be simpler to make all ApplyEnsemplePatch
sra1
2011/02/23 06:51:59
I would like to keep the entry point with as simpl
|
| + patch_path.value().c_str(), |
| + new_path.value().c_str()); |
| + |
| + if (status == courgette::C_OK) |
| + return; |
| + |
| + // Diagnose the error. |
| std::string old_buffer = ReadOrFail(old_file, "'old' input"); |
|
tommi (sloooow) - chröme
2011/02/23 06:35:59
remove these calls?
sra1
2011/02/23 06:51:59
If the file does not exist, this is what gives the
|
| + old_buffer.clear(); |
| std::string patch_buffer = ReadOrFail(patch_file, "'patch' input"); |
| + patch_buffer.clear(); |
| - courgette::SourceStream old_stream; |
| - courgette::SourceStream patch_stream; |
| - old_stream.Init(old_buffer); |
| - patch_stream.Init(patch_buffer); |
| - courgette::SinkStream new_stream; |
| - courgette::Status status = |
| - courgette::ApplyEnsemblePatch(&old_stream, &patch_stream, &new_stream); |
| + if (status == courgette::C_WRITE_OPEN_ERROR) |
| + Problem("Can't open output"); |
| + if (status == courgette::C_WRITE_ERROR) |
| + Problem("Can't write output"); |
| - if (status != courgette::C_OK) Problem("-apply failed."); |
| - |
| - WriteSinkToFile(&new_stream, new_file); |
| + Problem("-apply failed."); |
| } |
| void GenerateBSDiffPatch(const std::wstring& old_file, |