monotone

monotone Mtn Source Tree

Root/file_io.hh

1#ifndef __FILE_IO_H__
2#define __FILE_IO_H__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13#include "vocab.hh"
14#include "paths.hh"
15#include "sanity.hh"
16
17// this layer deals with talking to the filesystem, loading and saving
18// files, walking trees, etc.
19
20// this code mostly deals in any_path's, because these operations are too low
21// level for us to say whether applying them in any given case is valid or
22// not.
23
24// use I()
25void assert_path_is_nonexistent(any_path const & path);
26void assert_path_is_file(any_path const & path);
27void assert_path_is_directory(any_path const & path);
28
29// use N()
30void require_path_is_nonexistent(any_path const & path,
31 i18n_format const & message);
32void require_path_is_file(any_path const & path,
33 i18n_format const & message_if_nonexistent,
34 i18n_format const & message_if_directory);
35void require_path_is_directory(any_path const & path,
36 i18n_format const & message_if_nonexistent,
37 i18n_format const & message_if_file);
38
39// returns true if there is a file or directory at 'path'
40bool path_exists(any_path const & path);
41// returns true if there is a directory at 'path'
42bool directory_exists(any_path const & path);
43// returns true if there is a file at 'path'
44bool file_exists(any_path const & path);
45
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_shallow(any_path const & path);
56void delete_file_or_dir_shallow(any_path const & path);
57void delete_dir_recursive(any_path const & path);
58
59void move_file(any_path const & old_path,
60 any_path const & new_path);
61
62void move_dir(any_path const & old_path,
63 any_path const & new_path);
64
65// calls move_file or move_dir as appropriate
66void move_path(any_path const & old_path,
67 any_path const & new_path);
68
69void read_data(any_path const & path, data & data);
70
71void read_directory(any_path const & path,
72 std::vector<utf8> & files,
73 std::vector<utf8> & dirs);
74
75// This function knows that "-" means "stdin".
76void read_data_for_command_line(utf8 const & path, data & dat);
77
78// These are not any_path's because we make our write somewhat atomic -- we
79// first write to a temp file in _MTN/ (and it must be in _MTN/, not like /tmp
80// or something, because we can't necessarily atomic rename from /tmp to the
81// workspace). But that means we can't use it in general, only for the
82// workspace.
83void write_data(file_path const & path, data const & data);
84void write_data(bookkeeping_path const & path, data const & data);
85
86// Version that takes a system_path. To work with the "somewhat atomic"
87// goal, it also takes as an argument the place to put the temp file. Whoever
88// uses this is responsible to make sure that the tmpdir argument is somewhere
89// that the file can be atomically renamed from (same file system)
90void write_data(system_path const & path,
91 data const & data,
92 system_path const & tmpdir);
93
94class tree_walker
95{
96public:
97 // returns true if the directory should be descended into
98 virtual void visit_dir(file_path const & path);
99 virtual void visit_file(file_path const & path) = 0;
100 virtual ~tree_walker();
101};
102
103// from some safe sub-dir of cwd
104// file_path of "" means cwd
105void walk_tree(file_path const & path,
106 tree_walker & walker,
107 bool require_existing_path = true);
108
109
110
111// Local Variables:
112// mode: C++
113// fill-column: 76
114// c-file-style: "gnu"
115// indent-tabs-mode: nil
116// End:
117// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
118
119#endif // __FILE_IO_H__

Archive Download this file

Branches

Tags

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