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#include "platform-wrapped.hh"
17
18// this layer deals with talking to the filesystem, loading and saving
19// files, walking trees, etc.
20
21// this code mostly deals in any_path's, because these operations are too low
22// level for us to say whether applying them in any given case is valid or
23// not.
24
25// use I()
26void assert_path_is_nonexistent(any_path const & path);
27void assert_path_is_file(any_path const & path);
28void assert_path_is_directory(any_path const & path);
29
30// use N()
31void require_path_is_nonexistent(any_path const & path,
32 i18n_format const & message);
33void require_path_is_file(any_path const & path,
34 i18n_format const & message_if_nonexistent,
35 i18n_format const & message_if_directory);
36void require_path_is_directory(any_path const & path,
37 i18n_format const & message_if_nonexistent,
38 i18n_format const & message_if_file);
39
40// returns true if there is a file or directory at 'path'
41bool path_exists(any_path const & path);
42// returns true if there is a directory at 'path'
43bool directory_exists(any_path const & path);
44// returns true if there is a file at 'path'
45bool file_exists(any_path const & path);
46// returns true if there is a directory at 'path' with no files or sub-directories
47bool directory_empty(any_path const & path);
48
49
50// returns true if the string content is binary according to monotone heuristic
51bool guess_binary(std::string const & s);
52
53void mkdir_p(any_path const & path);
54void make_dir_for(any_path const & p);
55
56void delete_file(any_path const & path);
57void delete_dir_shallow(any_path const & path);
58void delete_file_or_dir_shallow(any_path const & path);
59void delete_dir_recursive(any_path const & path);
60
61void move_file(any_path const & old_path,
62 any_path const & new_path);
63
64void move_dir(any_path const & old_path,
65 any_path const & new_path);
66
67// calls move_file or move_dir as appropriate
68void move_path(any_path const & old_path,
69 any_path const & new_path);
70
71void read_data(any_path const & path, data & data);
72
73void read_directory(any_path const & path,
74 std::vector<path_component> & files,
75 std::vector<path_component> & dirs);
76
77void read_data_stdin(data & dat);
78
79// This function knows that "-" means "stdin".
80void read_data_for_command_line(utf8 const & path, data & dat);
81
82// These are not any_path's because we make our write somewhat atomic -- we
83// first write to a temp file in _MTN/ (and it must be in _MTN/, not like /tmp
84// or something, because we can't necessarily atomic rename from /tmp to the
85// workspace). But that means we can't use it in general, only for the
86// workspace.
87void write_data(file_path const & path, data const & data);
88void write_data(bookkeeping_path const & path, data const & data);
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
98// Identical to the above, but the file will be inaccessible to anyone but
99// the user. Use for things like private keys.
100void write_data_userprivate(system_path const & path,
101 data const & data,
102 system_path const & tmpdir);
103
104class tree_walker
105{
106public:
107 // returns true if the directory should be descended into
108 virtual bool visit_dir(file_path const & path);
109 virtual void visit_file(file_path const & path) = 0;
110 virtual ~tree_walker();
111};
112
113// from some safe sub-dir of cwd
114// file_path of "" means cwd
115void walk_tree(file_path const & path,
116 tree_walker & walker);
117
118
119bool ident_existing_file(file_path const & p, file_id & ident);
120bool ident_existing_file(file_path const & p, file_id & ident, path::status status);
121
122void calculate_ident(file_path const & file,
123 hexenc<id> & ident);
124
125// Local Variables:
126// mode: C++
127// fill-column: 76
128// c-file-style: "gnu"
129// indent-tabs-mode: nil
130// End:
131// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
132
133#endif // __FILE_IO_H__

Archive Download this file

Branches

Tags

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