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 "boost/format.hpp"
10
11#include "vocab.hh"
12#include "paths.hh"
13
14// this layer deals with talking to the filesystem, loading and saving
15// files, walking trees, etc.
16
17// this code mostly deals in any_path's, because these operations are too low
18// level for us to say whether applying them in any given case is valid or
19// not.
20
21struct lua_hooks;
22
23// use I()
24void assert_path_is_nonexistent(any_path const & path);
25void assert_path_is_file(any_path const & path);
26void assert_path_is_directory(any_path const & path);
27
28// use N()
29void require_path_is_nonexistent(any_path const & path,
30 boost::format const & message);
31void require_path_is_file(any_path const & path,
32 boost::format const & message_if_nonexistent,
33 boost::format const & message_if_directory);
34void require_path_is_directory(any_path const & path,
35 boost::format const & message_if_nonexistent,
36 boost::format const & message_if_file);
37
38// returns true if there is a file or directory at 'path'
39bool path_exists(any_path const & path);
40// returns true if there is a directory at 'path'
41bool directory_exists(any_path const & path);
42// returns true if there is a file at 'path'
43bool file_exists(any_path const & path);
44
45bool ident_existing_file(file_path const & p, file_id & ident, lua_hooks & lua);
46
47// returns true if the string content is binary according to monotone heuristic
48bool guess_binary(std::string const & s);
49void set_char_is_binary(char c, bool is_binary);
50
51void mkdir_p(any_path const & path);
52void make_dir_for(any_path const & p);
53
54void delete_file(any_path const & path);
55void delete_dir_recursive(any_path const & path);
56
57void move_file(any_path const & old_path,
58 any_path const & new_path);
59
60void move_dir(any_path const & old_path,
61 any_path const & new_path);
62
63// calls move_file or move_dir as appropriate
64void move_path(any_path const & old_path,
65 any_path const & new_path);
66
67void read_data(any_path const & path, data & data);
68void read_localized_data(file_path const & path,
69 data & dat,
70 lua_hooks & lua);
71
72void read_directory(system_path const & path,
73 std::vector<utf8> & files,
74 std::vector<utf8> & dirs);
75
76// This function knows that "-" means "stdin".
77void read_data_for_command_line(utf8 const & path, data & dat);
78
79// These are not any_path's because we make our write somewhat atomic -- we
80// first write to a temp file in MT/ (and it must be in MT/, not like /tmp or
81// something, because we can't necessarily atomic rename from /tmp to the
82// working copy). But that means we can't use it in general, only for the
83// working copy.
84void write_data(file_path const & path, data const & data);
85void write_data(bookkeeping_path const & path, data const & data);
86void write_localized_data(file_path const & path,
87 data const & dat,
88 lua_hooks & lua);
89
90// Version that takes a system_path. To work with the "somewhat atomic"
91// goal, it also takes as an argument the place to put the temp file. Whoever
92// uses this is responsible to make sure that the tmpdir argument is somewhere
93// that the file can be atomically renamed from (same file system)
94void write_data(system_path const & path,
95 data const & data,
96 system_path const & tmpdir);
97
98class tree_walker
99{
100public:
101 virtual void visit_file(file_path const & path) = 0;
102 virtual ~tree_walker();
103};
104
105// from some safe sub-dir of cwd
106// file_path of "" means cwd
107void walk_tree(file_path const & path,
108 tree_walker & walker,
109 bool require_existing_path = true);
110
111
112
113#endif // __FILE_IO_H__

Archive Download this file

Branches

Tags

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