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

Archive Download this file

Branches

Tags

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