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// returns true if there is a directory at 'path' with no files or sub-directories
46bool directory_empty(any_path const & path);
47
48
49// returns true if the string content is binary according to monotone heuristic
50bool guess_binary(std::string const & s);
51
52void mkdir_p(any_path const & path);
53void make_dir_for(any_path const & p);
54
55void delete_file(any_path const & path);
56void delete_dir_shallow(any_path const & path);
57void delete_file_or_dir_shallow(any_path const & path);
58void delete_dir_recursive(any_path const & path);
59
60void move_file(any_path const & old_path,
61 any_path const & new_path);
62
63void move_dir(any_path const & old_path,
64 any_path const & new_path);
65
66// calls move_file or move_dir as appropriate
67void move_path(any_path const & old_path,
68 any_path const & new_path);
69
70void read_data(any_path const & path, data & data);
71
72void read_directory(any_path const & path,
73 std::vector<utf8> & files,
74 std::vector<utf8> & dirs);
75
76void read_data_stdin(data & dat);
77
78// This function knows that "-" means "stdin".
79void read_data_for_command_line(utf8 const & path, data & dat);
80
81// These are not any_path's because we make our write somewhat atomic -- we
82// first write to a temp file in _MTN/ (and it must be in _MTN/, not like /tmp
83// or something, because we can't necessarily atomic rename from /tmp to the
84// workspace). But that means we can't use it in general, only for the
85// workspace.
86void write_data(file_path const & path, data const & data);
87void write_data(bookkeeping_path const & path, data const & data);
88
89// Version that takes a system_path. To work with the "somewhat atomic"
90// goal, it also takes as an argument the place to put the temp file. Whoever
91// uses this is responsible to make sure that the tmpdir argument is somewhere
92// that the file can be atomically renamed from (same file system)
93void write_data(system_path const & path,
94 data const & data,
95 system_path const & tmpdir);
96
97class tree_walker
98{
99public:
100 // returns true if the directory should be descended into
101 virtual bool visit_dir(file_path const & path);
102 virtual void visit_file(file_path const & path) = 0;
103 virtual ~tree_walker();
104};
105
106// from some safe sub-dir of cwd
107// file_path of "" means cwd
108void walk_tree(file_path const & path,
109 tree_walker & walker);
110
111
112bool ident_existing_file(file_path const & p, file_id & ident);
113void calculate_ident(file_path const & file,
114 hexenc<id> & ident);
115
116// Local Variables:
117// mode: C++
118// fill-column: 76
119// c-file-style: "gnu"
120// indent-tabs-mode: nil
121// End:
122// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
123
124#endif // __FILE_IO_H__

Archive Download this file

Branches

Tags

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