monotone

monotone Mtn Source Tree

Root/file_io.hh

1#ifndef __FILE_IO_H__
2#define __FILE_IO_H__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include "vocab.hh"
10
11// this layer deals with talking to the filesystem, loading and saving
12// files, walking trees, etc.
13//
14// we have *three* types of file path we're willing to deal with.
15//
16// - a boost::filesystem::path (fs::path)
17// [ defined in boost/filesystem/path.hpp ]
18// this is a generally portable path to anywhere in the fs
19//
20// - a local_path
21// [ defined in vocab.{hh,cc} ]
22// this is a path to a file in-or-under the current directory; it doesn't
23// escape cwd, and it's name restrictions are tighter than an fs::path,
24// as far as illegal characters and junk
25//
26// - a file_path
27// [ defined in vocab.{hh,cc} ]
28// this is a local_path which is *not* in the MT/ book-keeping
29// directory. in other words, it's a local_path which may permissibly be
30// part of a manifest.
31//
32// several functions in *this* file are defined on more than one of these
33// sorts of paths. the reason for the multiple path types is to avoid ever
34// constructing (and "forgetting to check the validity" of) an illegal
35// value in *other* parts of the code. this file contains stuff which is so
36// low level we can't mostly know whether what's being asked for is legal.
37
38struct lua_hooks;
39
40void save_initial_path();
41bool find_working_copy(fs::path const & search_root,
42 fs::path & working_copy_root,
43 fs::path & working_copy_restriction);
44
45fs::path mkpath(std::string const & s);
46
47std::string get_homedir();
48std::string absolutify(std::string const & path);
49std::string tilde_expand(std::string const & path);
50
51extern std::string const book_keeping_dir;
52
53// - file is inside the private MT/ directory
54bool book_keeping_file(local_path const & path);
55
56bool directory_exists(local_path const & path);
57bool directory_exists(file_path const & path);
58bool file_exists(local_path const & path);
59bool file_exists(file_path const & path);
60
61void mkdir_p(local_path const & path);
62void mkdir_p(file_path const & path);
63void make_dir_for(file_path const & p);
64
65void delete_file(file_path const & path);
66void delete_file(local_path const & path);
67void delete_dir_recursive(file_path const & path);
68void delete_dir_recursive(local_path const & path);
69
70void move_file(file_path const & old_path,
71 file_path const & new_path);
72void move_file(local_path const & old_path,
73 local_path const & new_path);
74
75void move_dir(file_path const & old_path,
76 file_path const & new_path);
77void move_dir(local_path const & old_path,
78 local_path const & new_path);
79
80void read_data(local_path const & path, data & data);
81void read_data(local_path const & path, base64< gzip<data> > & data);
82void read_data(file_path const & path, data & data);
83void read_data(file_path const & path, base64< gzip<data> > & data);
84void read_localized_data(file_path const & path,
85 data & dat,
86 lua_hooks & lua);
87void read_localized_data(file_path const & path,
88 base64< gzip<data> > & dat,
89 lua_hooks & lua);
90
91// This function knows that "-" means "stdin".
92void read_data_for_command_line(utf8 const & path, data & dat);
93
94void write_data(local_path const & path, data const & data);
95void write_data(local_path const & path, base64< gzip<data> > const & data);
96void write_data(file_path const & path, data const & data);
97void write_data(file_path const & path, base64< gzip<data> > const & data);
98void write_localized_data(file_path const & path,
99 data const & dat,
100 lua_hooks & lua);
101void write_localized_data(file_path const & path,
102 base64< gzip<data> > const & dat,
103 lua_hooks & lua);
104
105class tree_walker
106{
107public:
108 virtual void visit_file(file_path const & path) = 0;
109 virtual ~tree_walker();
110};
111
112// from cwd (nb: we can't describe cwd as a file_path)
113void walk_tree(tree_walker & walker);
114
115// from some safe sub-dir of cwd
116void walk_tree(file_path const & path,
117 tree_walker & walker,
118 bool require_existing_path = true);
119
120
121
122#endif // __FILE_IO_H__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status