monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone.alt_tmpdir: ca5fd78664d5951f


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone.alt_tmpdir: ca5fd78664d5951f916715dda310fee79c509be9
Date: Mon, 16 May 2011 21:47:21 +0200 (CEST)

revision:            ca5fd78664d5951f916715dda310fee79c509be9
date:                2011-05-16T19:46:47
author:              address@hidden
branch:              net.venge.monotone.alt_tmpdir
changelog:
start implementing tmpdir option

* src/cmd_ws_commit.cc (revert): add tmpdir_map to write_data
* src/file_io.cc (write_data):

* src/options_list.hh: define tmpdir option

* src/paths.hh: define file_path_map

* src/work.hh (workspace):
* src/work.cc (workspace): store tmpdir_map in workspace
  (read_options_file): read tmdir_map from _MTN/options
  (write_options_file): add fixme to write it as well
  (apply_delta): use it in apply_delta

* test/func/alt_tmpdir/__driver__.lua: improve test



manifest:
format_version "1"

new_manifest [91bdb751ced1d9904abc6444119c37dde696f73d]

old_revision [7cbdcccee91d72361dedcd7d99beb01697e2553a]

patch "src/cmd_ws_commit.cc"
 from [d9dbacb820c6d070c4952ee2b0f143e61e85631e]
   to [5a47738e20339d38cf4c6a7f2f2f6c38b10d3023]

patch "src/file_io.cc"
 from [76874e5ca4978bd0fd3ba183cd19edc3447ece0d]
   to [5ced2961491a37b61c27132328ea66de5bc34b43]

patch "src/file_io.hh"
 from [1ecc0d6d6f9dddeb676ac95ca074c2dfb82e58d0]
   to [732a7f9ea3dbe91e34cba7cb0d8278063e0a4e1e]

patch "src/options_list.hh"
 from [0462e302b89179f4acb28ecb91f4255140d4a4a7]
   to [3030630476df45384bd7333cca84846ea867b696]

patch "src/paths.hh"
 from [2939f11db21e23d68530ed7415b9bdfa8dfd5a20]
   to [8513b65d9c07fafa3f82094a3080e915c095da16]

patch "src/work.cc"
 from [36e5dcda8cf09c9054cb88e6165707112ba9ac03]
   to [820f608221065145537ffa27b89d86827d78f890]

patch "src/work.hh"
 from [00e100f44763cad0019683c16c4a13d53a94d5e0]
   to [d790bd2cac676969e4721c14a948dff1eb614334]

patch "test/func/alt_tmpdir/__driver__.lua"
 from [1a104f34a0f9484bed0d6b6471f1269803448ed6]
   to [7fe3966fdfd7c95213ba96a913d4d194ffb2889f]

patch "test/func/alt_tmpdir/options_line.text"
 from [30a5ae5a444adef0029e1c8db80e02bc120ec720]
   to [658da10d7b995eed5903553a8e808ab2fad8a0d2]
============================================================
--- src/file_io.cc	76874e5ca4978bd0fd3ba183cd19edc3447ece0d
+++ src/file_io.cc	5ced2961491a37b61c27132328ea66de5bc34b43
@@ -1,4 +1,5 @@
 // Copyright (C) 2002 Graydon Hoare <address@hidden>
+// Copyright (C) 2011 Stephen Leake <address@hidden>
 //
 // This program is made available under the GNU GPL version 2.0 or
 // greater. See the accompanying file COPYING for details.
@@ -339,11 +340,24 @@ void
 }
 
 void
-write_data(file_path const & path, data const & dat)
+write_data(file_path const & path,
+           data const & dat,
+           file_path_map const & tmpdir_map)
 {
-  // use the bookkeeping root as the temporary directory.
-  assert_path_is_directory(bookkeeping_root);
-  write_data_impl(path, dat, bookkeeping_root, false);
+  // use the bookkeeping root as the temporary directory, unless overridden
+  // by a tmpdir option.
+
+  // FIXME: match path prefix, not entire path; need alternate compare operator for find
+  std::map<file_path, file_path>::const_iterator i = tmpdir_map.find(path);
+  any_path tmp = any_path(bookkeeping_root);
+
+  if (i != tmpdir_map.end())
+    {
+      tmp = i->second;
+    }
+
+  assert_path_is_directory(tmp);
+  write_data_impl(path, dat, tmp, false);
 }
 
 void
============================================================
--- src/file_io.hh	1ecc0d6d6f9dddeb676ac95ca074c2dfb82e58d0
+++ src/file_io.hh	732a7f9ea3dbe91e34cba7cb0d8278063e0a4e1e
@@ -1,4 +1,5 @@
 // Copyright (C) 2002 Graydon Hoare <address@hidden>
+// Copyright (C) 2011 Stephen Leake <address@hidden>
 //
 // This program is made available under the GNU GPL version 2.0 or
 // greater. See the accompanying file COPYING for details.
@@ -83,7 +84,13 @@ void read_data_for_command_line(utf8 con
 // or something, because we can't necessarily atomic rename from /tmp to the
 // workspace).  But that means we can't use it in general, only for the
 // workspace.
-void write_data(file_path const & path, data const & data);
+//
+// alt_tmpdir_map allows using alternate temp file directories for parts of
+// the workspace. This allows, for example, putting part of the workspace on
+// an NFS mounted drive.
+void write_data(file_path const & path,
+                data const & data,
+                file_path_map const & tmpdir_map);
 void write_data(bookkeeping_path const & path, data const & data);
 
 // Version that takes a system_path. To work with the "somewhat atomic"
============================================================
--- src/work.cc	36e5dcda8cf09c9054cb88e6165707112ba9ac03
+++ src/work.cc	820f608221065145537ffa27b89d86827d78f890
@@ -1,4 +1,4 @@
-// Copyright (C) 2009, 2010 Stephen Leake <address@hidden>
+// Copyright (C) 2009 - 2011 Stephen Leake <address@hidden>
 // Copyright (C) 2002 Graydon Hoare <address@hidden>
 //
 // This program is made available under the GNU GPL version 2.0 or
@@ -191,19 +191,20 @@ workspace::workspace(app_state & app)
 
 // Normal-use constructor.
 workspace::workspace(app_state & app)
-  : lua(app.lua)
+  : lua(app.lua), tmpdir_map(app.opts.tmpdir)
 {
   require_workspace();
 }
 
 workspace::workspace(app_state & app, i18n_format const & explanation)
-  : lua(app.lua)
+  : lua(app.lua), tmpdir_map(app.opts.tmpdir)
 {
   require_workspace(explanation);
 }
 
-workspace::workspace(lua_hooks & lua, i18n_format const & explanation)
-  : lua(lua)
+workspace::workspace(lua_hooks & lua,
+                     i18n_format const & explanation)
+  : lua(lua), tmpdir_map(file_path_map())
 {
   require_workspace(explanation);
 }
@@ -517,6 +518,22 @@ read_options_file(any_path const & optsp
           opts.key_dir = system_path(val, origin::workspace);
           opts.key_dir_given = true;
         }
+      else if (opt == "tmpdir")
+        {
+          // val is 'path1=path2'
+          size_t const path1_last = val.find("=") - 1;
+          try
+            {
+              file_path path1 = file_path_internal(val.substr(0, path1_last + 1));
+              file_path path2 = file_path_internal(val.substr(path1_last + 1));
+              opts.tmpdir.insert(std::make_pair(path1, path2));
+            }
+          catch (std::exception & e)
+            {
+              W(F("could not parse key 'tmpdir' (value '%s') in options file '%s' - ignored")
+                % val % optspath);
+            }
+        }
       else
         W(F("unrecognized key '%s' in options file '%s' - ignored")
           % opt % optspath);
@@ -549,6 +566,8 @@ write_options_file(bookkeeping_path cons
   if (!opts.key_dir.as_internal().empty())
     st.push_str_pair(symbol("keydir"), opts.key_dir.as_internal());
 
+  // FIXME: write tmpdir
+
   basic_io::printer pr;
   pr.print_stanza(st);
   try
@@ -1281,6 +1300,7 @@ path_for_detached_nids()
 static inline bookkeeping_path
 path_for_detached_nids()
 {
+  // FIXME: this needs to use tmpdir_map
   return bookkeeping_root / "detached";
 }
 
@@ -1432,7 +1452,7 @@ editable_working_tree::apply_delta(file_
 
   file_data dat;
   source.get_version(new_id, dat);
-  write_data(pth, dat.inner());
+  write_data(pth, dat.inner(), work.tmpdir_map);
 }
 
 void
@@ -2180,7 +2200,11 @@ workspace::perform_content_update(roster
   roster_t test_roster;
   temp_node_id_source nis;
   set<file_path> known;
+
+  // FIXME: this must be a list, from tmpdir_map
+  // which means it may not be a bookkeeping path
   bookkeeping_path detached = path_for_detached_nids();
+
   bool moved_conflicting = false;
 
   E(!directory_exists(detached), origin::user,
============================================================
--- src/work.hh	00e100f44763cad0019683c16c4a13d53a94d5e0
+++ src/work.hh	d790bd2cac676969e4721c14a948dff1eb614334
@@ -1,4 +1,5 @@
 // Copyright (C) 2002 Graydon Hoare <address@hidden>
+// Copyright (C) 2011 Stephen Leake <address@hidden>
 //
 // This program is made available under the GNU GPL version 2.0 or
 // greater. See the accompanying file COPYING for details.
@@ -128,8 +129,12 @@ public:
   // definitely is.
   explicit workspace(app_state & app);
   explicit workspace(app_state & app, i18n_format const & explanation);
-  explicit workspace(lua_hooks & lua, i18n_format const & explanation);
 
+  // this is only used by selectors to get info about the workspace, so it
+  // doesn't need a tmpdir_map
+  explicit workspace(lua_hooks & lua,
+                     i18n_format const & explanation);
+
   // Methods for manipulating the workspace's content.
   void find_missing(roster_t const & new_roster_shape,
                     node_restriction const & mask,
@@ -293,6 +298,9 @@ public:
   // that exists, is unknown, and matches one of these regexps is treated as
   // if it did not exist, instead of being an unknown file.
   bool ignore_file(file_path const & path);
+
+  file_path_map const & tmpdir_map;
+
 };
 
 // This object turns the workspace ignore_file method into a path predicate,
============================================================
--- src/paths.hh	2939f11db21e23d68530ed7415b9bdfa8dfd5a20
+++ src/paths.hh	8513b65d9c07fafa3f82094a3080e915c095da16
@@ -1,5 +1,5 @@
-// Copyright (C) 2005 Nathaniel Smith <address@hidden>
-//               2008, 2010 Stephen Leake <address@hidden>
+// Copyright (C) 2005, 2011 Nathaniel Smith <address@hidden>
+//               2008, 2010, 2011 Stephen Leake <address@hidden>
 //
 // This program is made available under the GNU GPL version 2.0 or
 // greater. See the accompanying file COPYING for details.
@@ -484,6 +484,8 @@ void reset_std_paths(void);
 // reset path globals to uninitialized; should be done for each new command.
 void reset_std_paths(void);
 
+typedef std::map<file_path, file_path> file_path_map; // need a named type for options
+
 file_path
 find_new_path_for(std::map<file_path, file_path> const & renames,
                   file_path const & old_path);
============================================================
--- src/cmd_ws_commit.cc	d9dbacb820c6d070c4952ee2b0f143e61e85631e
+++ src/cmd_ws_commit.cc	5a47738e20339d38cf4c6a7f2f2f6c38b10d3023
@@ -489,7 +489,7 @@ revert(app_state & app,
               L(FL("writing file %s to %s")
                 % f->content % path);
               db.get_file_version(f->content, dat);
-              write_data(path, dat.inner());
+              write_data(path, dat.inner(), app.opts.tmpdir);
             }
         }
       else
============================================================
--- src/options_list.hh	0462e302b89179f4acb28ecb91f4255140d4a4a7
+++ src/options_list.hh	3030630476df45384bd7333cca84846ea867b696
@@ -1,5 +1,5 @@
 // Copyright (C) 2006 Timothy Brownawell <address@hidden>
-//               2008-2010 Stephen Leake <address@hidden>
+//               2008-2011 Stephen Leake <address@hidden>
 //
 // This program is made available under the GNU GPL version 2.0 or
 // greater. See the accompanying file COPYING for details.
@@ -154,6 +154,19 @@ void set_simple_option(enum_string_set &
 template<>
 void set_simple_option(enum_string_set & t, std::string const & arg)
 { t.add(arg); }
+void set_simple_option(file_path_map & t, std::string const & arg)
+{
+  // arg is 'path1=path2'
+  size_t const path1_last = arg.find("=") - 1;
+  try
+    {
+      file_path path1 = file_path_internal(arg.substr(0, path1_last + 1));
+      file_path path2 = file_path_internal(arg.substr(path1_last + 1));
+      t.insert(std::make_pair(path1, path2));
+    }
+  catch (std::exception & e)
+    { throw bad_arg_internal(e.what()); }
+}
 
 # define SIMPLE_OPTION_BODY(name) { set_simple_option(name, arg); }
 #else
@@ -650,6 +663,9 @@ SIMPLE_OPTION(export_marks, "export-mark
 SIMPLE_OPTION(export_marks, "export-marks", system_path,
               gettext_noop("save the internal marks table after exporting revisions"))
 
+SIMPLE_INITIALIZED_OPTION(tmpdir, "tmpdir", file_path_map, file_path_map(),
+              gettext_noop("list of alternate temp directories for writing files"))
+
 // clean up after ourselves
 #undef SIMPLE_OPTION
 #undef SIMPLE_OPTION_BODY
============================================================
--- test/func/alt_tmpdir/__driver__.lua	1a104f34a0f9484bed0d6b6471f1269803448ed6
+++ test/func/alt_tmpdir/__driver__.lua	7fe3966fdfd7c95213ba96a913d4d194ffb2889f
@@ -14,8 +14,12 @@ mkdir("nfs_mounted")
 addfile("local/local-file0", "local file 0\n")
 
 mkdir("nfs_mounted")
-addfile("nfs_mounted/nfs_mounted-file0", "nfs_mounted file 0\n")
+addfile("nfs_mounted/file0", "nfs_mounted file 0\n")
 
+-- alt_tmpdir matches tree rooted at nfs_mounted
+mkdir("nfs_mounted/dir1")
+addfile("nfs_mounted/dir1/file0", "dir1/nfs_mounted file 1\n")
+
 commit()
 rev0 = base_revision()
 
@@ -23,7 +27,7 @@ addfile("nfs_mounted/file1", "nfs_mounte
 addfile("local/file2", "local file 2\n")
 
 addfile("nfs_mounted/file1", "nfs_mounted file 1\n")
-addfile("nfs_mounted/file2", "nfs_mounted file 2\n")
+addfile("nfs_mounted/dir1/file1", "dir1/nfs_mounted file 1\n")
 
 commit()
 rev1 = base_revision()
@@ -36,5 +40,6 @@ check(mtn("update"), 0, nil, true)
 mkdir("nfs_mounted/tmp")
 
 check(mtn("update"), 0, nil, true)
+-- FIXME: no way to see use of nfs_mounted/tmp?
 
 -- end of file
============================================================
--- test/func/alt_tmpdir/options_line.text	30a5ae5a444adef0029e1c8db80e02bc120ec720
+++ test/func/alt_tmpdir/options_line.text	658da10d7b995eed5903553a8e808ab2fad8a0d2
@@ -1 +1 @@
-  tmpdir "nfs_mounted" "nfs_mounted/tmp"
+  tmpdir "nfs_mounted=nfs_mounted/tmp"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]