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();
41
42fs::path mkpath(std::string const & s);
43
44std::string get_homedir();
45std::string absolutify(std::string const & path);
46std::string tilde_expand(std::string const & path);
47
48extern std::string const book_keeping_dir;
49
50// - file is inside the private MT/ directory
51bool book_keeping_file(local_path const & path);
52
53bool directory_exists(local_path const & path);
54bool file_exists(local_path const & path);
55bool file_exists(file_path const & path);
56
57void mkdir_p(local_path const & path);
58void mkdir_p(file_path const & path);
59void make_dir_for(file_path const & p);
60
61void delete_file(local_path const & path);
62void delete_file(file_path const & path);
63
64void move_file(file_path const & old_path,
65 file_path const & new_path);
66
67void read_data(local_path const & path, data & data);
68void read_data(local_path const & path, base64< gzip<data> > & data);
69void read_data(file_path const & path, data & data);
70void read_data(file_path const & path, base64< gzip<data> > & data);
71void read_localized_data(file_path const & path,
72 data & dat,
73 lua_hooks & lua);
74void read_localized_data(file_path const & path,
75 base64< gzip<data> > & dat,
76 lua_hooks & lua);
77
78void write_data(local_path const & path, data const & data);
79void write_data(local_path const & path, base64< gzip<data> > const & data);
80void write_data(file_path const & path, data const & data);
81void write_data(file_path const & path, base64< gzip<data> > const & data);
82void write_localized_data(file_path const & path,
83 data const & dat,
84 lua_hooks & lua);
85void write_localized_data(file_path const & path,
86 base64< gzip<data> > const & dat,
87 lua_hooks & lua);
88
89class tree_walker
90{
91public:
92 virtual void visit_file(file_path const & path) = 0;
93 virtual ~tree_walker();
94};
95
96// from cwd (nb: we can't describe cwd as a file_path)
97void walk_tree(tree_walker & walker);
98
99// from some safe sub-dir of cwd
100void walk_tree(file_path const & path,
101 tree_walker & walker);
102
103
104
105#endif // __FILE_IO_H__

Archive Download this file

Branches

Tags

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