# # patch "ChangeLog" # from [8e048f4e850b805915266d7c96a991c41a5a6056] # to [cd767166121539b7dcd8c737b4622f81ab555397] # # patch "file_io.cc" # from [febfb6d77ff68b672149e4eaebe863d681f936a7] # to [041a81978fe4ec6eb0fae72663d56474a5c34f92] # # patch "file_io.hh" # from [8adb1eccca1a007c6be0f14e7f7d66c0265d971a] # to [ccb9ff07ec95081cea4cab9278e6b5ec219dd86c] # ======================================================================== --- ChangeLog 8e048f4e850b805915266d7c96a991c41a5a6056 +++ ChangeLog cd767166121539b7dcd8c737b4622f81ab555397 @@ -1,5 +1,10 @@ 2005-08-25 Nathaniel Smith + * file_io.cc (read_localized_data, read_data_for_command_line) + (write_localized_data, write_data, write_data_impl): Implement. + +2005-08-25 Nathaniel Smith + * file_io.cc (read_data): Implement. Remove the base64> versions. ======================================================================== --- file_io.cc febfb6d77ff68b672149e4eaebe863d681f936a7 +++ file_io.cc 041a81978fe4ec6eb0fae72663d56474a5c34f92 @@ -216,7 +216,7 @@ } void -read_localized_data(file_path const & path, +read_localized_data(any_path const & path, data & dat, lua_hooks & lua) { @@ -266,10 +266,7 @@ if (path() == "-") read_data_stdin(dat); else - { - N(fs::exists(localized(path)), F("file '%s' does not exist") % path); - read_data_impl(localized(path), dat); - } + read_data(file_path_external(path), dat); } @@ -280,48 +277,45 @@ static void -write_data_impl(fs::path const & p, +write_data_impl(any_path const & p, data const & dat) { - if (fs::exists(p) && fs::is_directory(p)) - throw oops("file '" + p.string() + "' cannot be over-written as data; it is a directory"); + N(!directory_exists(p), + F("file '%s' cannot be overwritten as data; it is a directory") % p); - fs::create_directories(mkpath(p.branch_path().string())); + make_dir_for(p); // we write, non-atomically, to MT/data.tmp. // nb: no mucking around with multiple-writer conditions. we're a // single-user single-threaded program. you get what you paid for. - fs::path mtdir = mkpath(book_keeping_dir); - fs::create_directories(mtdir); - fs::path tmp = mtdir / "data.tmp"; + assert_path_is_directory(bookkeeping_root); + bookkeeping_path tmp = bookkeeping_root / "data.tmp"; { // data.tmp opens - ofstream file(tmp.string().c_str(), + ofstream file(tmp.as_external().c_str(), ios_base::out | ios_base::trunc | ios_base::binary); - if (!file) - throw oops(string("cannot open file ") + tmp.string() + " for writing"); + N(file, F("cannot open file %s for writing") % tmp); Botan::Pipe pipe(new Botan::DataSink_Stream(file)); pipe.process_msg(dat()); // data.tmp closes } - if (fs::exists(p)) - N(fs::remove(p), - F("removing %s failed") % p.string()); - fs::rename(tmp, p); + if (path_exists(p)) + N(fs::remove(p.as_external()), F("removing %s failed") % p); + fs::rename(tmp.as_external(), p.as_external()); } void -write_data(local_path const & path, data const & dat) +write_data(file_path const & path, data const & dat) { - write_data_impl(localized(path), dat); + write_data_impl(path, dat); } void -write_data(file_path const & path, data const & dat) +write_data(bookkeeping_path const & path, data const & dat) { - write_data_impl(localized(path), dat); + write_data_impl(path, dat); } void @@ -352,37 +346,6 @@ write_data(path, data(tmp2)); } -void -write_localized_data(file_path const & path, - base64< gzip > const & dat, - lua_hooks & lua) -{ - gzip data_decoded; - data data_decompressed; - decode_base64(dat, data_decoded); - decode_gzip(data_decoded, data_decompressed); - write_localized_data(path, data_decompressed, lua); -} - -void -write_data(local_path const & path, - base64< gzip > const & dat) -{ - gzip data_decoded; - data data_decompressed; - decode_base64(dat, data_decoded); - decode_gzip(data_decoded, data_decompressed); - write_data_impl(localized(path), data_decompressed); -} - -void -write_data(file_path const & path, - base64< gzip > const & dat) -{ - write_data(local_path(path()), dat); -} - - tree_walker::~tree_walker() {} static void ======================================================================== --- file_io.hh 8adb1eccca1a007c6be0f14e7f7d66c0265d971a +++ file_io.hh ccb9ff07ec95081cea4cab9278e6b5ec219dd86c @@ -90,14 +90,16 @@ // This function knows that "-" means "stdin". void read_data_for_command_line(utf8 const & path, data & dat); -void write_data(any_path const & path, data const & data); -void write_data(any_path const & path, base64< gzip > const & data); +// These are not any_path's because we make our write somewhat atomic -- we +// first write to a temp file in MT/ (and it must be in MT/, not like /tmp or +// something, because we can't necessarily atomic rename from /tmp to the +// working copy). But that means we can't use it in general, only for the +// working copy. +void write_data(file_path const & path, data const & data); +void write_data(bookkeeping_path const & path, data const & data); void write_localized_data(file_path const & path, data const & dat, lua_hooks & lua); -void write_localized_data(file_path const & path, - base64< gzip > const & dat, - lua_hooks & lua); class tree_walker {