Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 183 lines (159 sloc) 5.374 kb
ec250c6 Andreas Ericsson Remove config.h and make fileops an internal API
ageric authored
1 /*
5e0de32 Michael Schubert Update Copyright header
schu authored
2 * Copyright (C) 2009-2012 the libgit2 contributors
ec250c6 Andreas Ericsson Remove config.h and make fileops an internal API
ageric authored
3 *
bb742ed Vicent Marti Cleanup legal data
vmg authored
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
ec250c6 Andreas Ericsson Remove config.h and make fileops an internal API
ageric authored
6 */
7 #ifndef INCLUDE_fileops_h__
8 #define INCLUDE_fileops_h__
9
5690f02 Shawn O. Pearce Rewrite git_foreach_dirent into gitfo_dirent
spearce authored
10 #include "common.h"
79ca2ed win32: Add routines to abstract memory-mapped file functions
Ramsay Jones authored
11 #include "map.h"
f79026b Vicent Marti fileops: Cleanup
vmg authored
12 #include "posix.h"
13 #include "path.h"
14
15 /**
16 * Filebuffer methods
17 *
18 * Read whole files into an in-memory buffer for processing
19 */
13224ea Vicent Marti buffer: Unify `git_fbuffer` and `git_buf`
vmg authored
20 extern int git_futils_readbuffer(git_buf *obj, const char *path);
21 extern int git_futils_readbuffer_updated(git_buf *obj, const char *path, time_t *mtime, int *updated);
f79026b Vicent Marti fileops: Cleanup
vmg authored
22
23 /**
24 * File utils
25 *
26 * These are custom filesystem-related helper methods. They are
27 * rather high level, and wrap the underlying POSIX methods
28 *
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
29 * All these methods return 0 on success,
f79026b Vicent Marti fileops: Cleanup
vmg authored
30 * or an error code on failure and an error message is set.
31 */
32
33 /**
34 * Create and open a file, while also
35 * creating all the folders in its path
36 */
ce8cd00 Brodie Rao fileops/repository: create (most) directories with 0777 permissions
brodie authored
37 extern int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode);
f79026b Vicent Marti fileops: Cleanup
vmg authored
38
39 /**
40 * Create an open a process-locked file
41 */
3312704 Brodie Rao fileops/posix: replace usage of "int mode" with "mode_t mode"
brodie authored
42 extern int git_futils_creat_locked(const char *path, const mode_t mode);
f79026b Vicent Marti fileops: Cleanup
vmg authored
43
44 /**
45 * Create an open a process-locked file, while
46 * also creating all the folders in its path
47 */
ce8cd00 Brodie Rao fileops/repository: create (most) directories with 0777 permissions
brodie authored
48 extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode);
f79026b Vicent Marti fileops: Cleanup
vmg authored
49
50 /**
51 * Create a path recursively
dc07184 nulltoken fileops: Make git_futils_mkdir_r() able to cope with Windows network pat...
nulltoken authored
52 *
53 * If a base parameter is being passed, it's expected to be valued with a path pointing to an already
54 * exisiting directory.
f79026b Vicent Marti fileops: Cleanup
vmg authored
55 */
9776928 Russell Belfer Use git_buf for path storage instead of stack-based buffers
arrbee authored
56 extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode);
f79026b Vicent Marti fileops: Cleanup
vmg authored
57
58 /**
59 * Create all the folders required to contain
60 * the full path of a file
61 */
ce8cd00 Brodie Rao fileops/repository: create (most) directories with 0777 permissions
brodie authored
62 extern int git_futils_mkpath2file(const char *path, const mode_t mode);
f79026b Vicent Marti fileops: Cleanup
vmg authored
63
555aa45 nulltoken fileops: Make git_futils_mkdir_r() able to skip non-empty directories
nulltoken authored
64 typedef enum {
65 GIT_DIRREMOVAL_EMPTY_HIERARCHY = 0,
66 GIT_DIRREMOVAL_FILES_AND_DIRS = 1,
67 GIT_DIRREMOVAL_ONLY_EMPTY_DIRS = 2,
68 } git_directory_removal_type;
69
f79026b Vicent Marti fileops: Cleanup
vmg authored
70 /**
1744faf Russell Belfer Move path related functions from fileops to path
arrbee authored
71 * Remove path and any files and directories beneath it.
555aa45 nulltoken fileops: Make git_futils_mkdir_r() able to skip non-empty directories
nulltoken authored
72 *
73 * @param path Path to to top level directory to process.
74 *
75 * @param removal_type GIT_DIRREMOVAL_EMPTY_HIERARCHY to remove a hierarchy
76 * of empty directories (will fail if any file is found), GIT_DIRREMOVAL_FILES_AND_DIRS
77 * to remove a hierarchy of files and folders, GIT_DIRREMOVAL_ONLY_EMPTY_DIRS to only remove
78 * empty directories (no failure on file encounter).
79 *
80 * @return 0 on success; -1 on error.
df743c7 Russell Belfer Initial implementation of gitignore support
arrbee authored
81 */
1a2b872 Carlos Martín Nieto Typedefs don't have enum in front
carlosmn authored
82 extern int git_futils_rmdir_r(const char *path, git_directory_removal_type removal_type);
df743c7 Russell Belfer Initial implementation of gitignore support
arrbee authored
83
84 /**
9776928 Russell Belfer Use git_buf for path storage instead of stack-based buffers
arrbee authored
85 * Create and open a temporary file with a `_git2_` suffix.
86 * Writes the filename into path_out.
87 * @return On success, an open file descriptor, else an error code < 0.
f79026b Vicent Marti fileops: Cleanup
vmg authored
88 */
9776928 Russell Belfer Use git_buf for path storage instead of stack-based buffers
arrbee authored
89 extern int git_futils_mktmp(git_buf *path_out, const char *filename);
f79026b Vicent Marti fileops: Cleanup
vmg authored
90
91 /**
92 * Move a file on the filesystem, create the
93 * destination path if it doesn't exist
94 */
ce8cd00 Brodie Rao fileops/repository: create (most) directories with 0777 permissions
brodie authored
95 extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode);
f79026b Vicent Marti fileops: Cleanup
vmg authored
96
97 /**
deafee7 Russell Belfer Continue error conversion
arrbee authored
98 * Open a file readonly and set error if needed.
ae9e29f Russell Belfer Migrating diff to new error handling
arrbee authored
99 */
deafee7 Russell Belfer Continue error conversion
arrbee authored
100 extern int git_futils_open_ro(const char *path);
ae9e29f Russell Belfer Migrating diff to new error handling
arrbee authored
101
102 /**
f79026b Vicent Marti fileops: Cleanup
vmg authored
103 * Get the filesize in bytes of a file
104 */
105 extern git_off_t git_futils_filesize(git_file fd);
502acd1 win32: Add missing include for mkdir() and rmdir()
Ramsay Jones authored
106
74fa4bf Russell Belfer Update diff to use iterators
arrbee authored
107 #define GIT_MODE_PERMS_MASK 0777
108 #define GIT_CANONICAL_PERMS(MODE) (((MODE) & 0100) ? 0755 : 0644)
109 #define GIT_MODE_TYPE(MODE) ((MODE) & ~GIT_MODE_PERMS_MASK)
110
5690f02 Shawn O. Pearce Rewrite git_foreach_dirent into gitfo_dirent
spearce authored
111 /**
b6c93ae Russell Belfer Uniform iterators for trees, index, and workdir
arrbee authored
112 * Convert a mode_t from the OS to a legal git mode_t value.
113 */
114 extern mode_t git_futils_canonical_mode(mode_t raw_mode);
115
116
117 /**
20e7f42 Shawn O. Pearce Add a simple mmap wrapper for cross-platform mmap usage
spearce authored
118 * Read-only map all or part of a file into memory.
119 * When possible this function should favor a virtual memory
120 * style mapping over some form of malloc()+read(), as the
121 * data access will be random and is not likely to touch the
122 * majority of the region requested.
123 *
124 * @param out buffer to populate with the mapping information.
125 * @param fd open descriptor to configure the mapping from.
126 * @param begin first byte to map, this should be page aligned.
127 * @param end number of bytes to map.
128 * @return
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
129 * - 0 on success;
130 * - -1 on error.
20e7f42 Shawn O. Pearce Add a simple mmap wrapper for cross-platform mmap usage
spearce authored
131 */
f79026b Vicent Marti fileops: Cleanup
vmg authored
132 extern int git_futils_mmap_ro(
79ca2ed win32: Add routines to abstract memory-mapped file functions
Ramsay Jones authored
133 git_map *out,
20e7f42 Shawn O. Pearce Add a simple mmap wrapper for cross-platform mmap usage
spearce authored
134 git_file fd,
f0bde7f Alex Budovski Revised platform types to use 'best supported' size.
scorpion007 authored
135 git_off_t begin,
20e7f42 Shawn O. Pearce Add a simple mmap wrapper for cross-platform mmap usage
spearce authored
136 size_t len);
137
138 /**
74fa4bf Russell Belfer Update diff to use iterators
arrbee authored
139 * Read-only map an entire file.
140 *
141 * @param out buffer to populate with the mapping information.
142 * @param path path to file to be opened.
143 * @return
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
144 * - 0 on success;
145 * - GIT_ENOTFOUND if not found;
146 * - -1 on an unspecified OS related error.
74fa4bf Russell Belfer Update diff to use iterators
arrbee authored
147 */
148 extern int git_futils_mmap_ro_file(
149 git_map *out,
150 const char *path);
151
152 /**
20e7f42 Shawn O. Pearce Add a simple mmap wrapper for cross-platform mmap usage
spearce authored
153 * Release the memory associated with a previous memory mapping.
154 * @param map the mapping description previously configured.
155 */
f79026b Vicent Marti fileops: Cleanup
vmg authored
156 extern void git_futils_mmap_free(git_map *map);
20e7f42 Shawn O. Pearce Add a simple mmap wrapper for cross-platform mmap usage
spearce authored
157
158 /**
73b5145 Russell Belfer Add support for macros and cache flush API.
arrbee authored
159 * Find a "global" file (i.e. one in a user's home directory).
160 *
161 * @param pathbuf buffer to write the full path into
162 * @param filename name of file to find in the home directory
163 * @return
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
164 * - 0 if found;
73b5145 Russell Belfer Add support for macros and cache flush API.
arrbee authored
165 * - GIT_ENOTFOUND if not found;
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
166 * - -1 on an unspecified OS related error.
73b5145 Russell Belfer Add support for macros and cache flush API.
arrbee authored
167 */
168 extern int git_futils_find_global_file(git_buf *path, const char *filename);
169
170 /**
171 * Find a "system" file (i.e. one shared for all users of the system).
172 *
173 * @param pathbuf buffer to write the full path into
174 * @param filename name of file to find in the home directory
175 * @return
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
176 * - 0 if found;
73b5145 Russell Belfer Add support for macros and cache flush API.
arrbee authored
177 * - GIT_ENOTFOUND if not found;
0d0fa7c Russell Belfer Convert attr, ignore, mwindow, status to new errors
arrbee authored
178 * - -1 on an unspecified OS related error.
73b5145 Russell Belfer Add support for macros and cache flush API.
arrbee authored
179 */
180 extern int git_futils_find_system_file(git_buf *path, const char *filename);
181
ec250c6 Andreas Ericsson Remove config.h and make fileops an internal API
ageric authored
182 #endif /* INCLUDE_fileops_h__ */
Something went wrong with that request. Please try again.