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

Archive Download this file

Branches

Tags

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