summaryrefslogtreecommitdiff
path: root/src/filebuf.c
Commit message (Collapse)AuthorAgeFilesLines
* filebuf: use hashes not oidsEdward Thomson2021-11-221-3/+3
| | | | | The filebuf functions should use hashes directly, not indirectly using the oid functions.
* path: separate git-specific path functions from utilEdward Thomson2021-11-091-7/+7
| | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* hash: hash functions operate on byte arrays not git_oidsEdward Thomson2021-10-021-1/+1
| | | | | | Separate the concerns of the hash functions from the git_oid functions. The git_oid structure will need to understand either SHA1 or SHA256; the hash functions should only deal with the appropriate one of these.
* hash: accept the algorithm in inputsEdward Thomson2021-10-011-1/+1
|
* filebuf: use GIT_ASSERTEdward Thomson2020-11-271-7/+9
|
* refs: fix locks getting forcibly removedSebastian Henke2019-10-101-9/+5
| | | | | | | | | | | | | | | | | The flag GIT_FILEBUF_FORCE currently does two things: 1. It will cause the filebuf to create non-existing leading directories for the file that is about to be written. 2. It will forcibly remove any pre-existing locks. While most call sites actually do want (1), they do not want to remove pre-existing locks, as that renders the locking mechanisms effectively useless. Introduce a new flag `GIT_FILEBUF_CREATE_LEADING_DIRS` to separate both behaviours cleanly from each other and convert callers to use it instead of `GIT_FILEBUF_FORCE` to have them honor locked files correctly. As this conversion removes all current users of `GIT_FILEBUF_FORCE`, this commit removes the flag altogether.
* fileops: rename to "futils.h" to match function signaturesPatrick Steinhardt2019-07-201-1/+1
| | | | | | | | | Our file utils functions all have a "futils" prefix, e.g. `git_futils_touch`. One would thus naturally guess that their definitions and implementation would live in files "futils.h" and "futils.c", respectively, but in fact they live in "fileops.h". Rename the files to match expectations.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-24/+24
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-4/+4
|
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* Merge pull request #4030 from libgit2/ethomson/fsyncEdward Thomson2017-03-221-0/+11
|\ | | | | fsync all the things
| * fsync parent directories when fsyncingEdward Thomson2017-02-281-0/+3
| | | | | | | | | | | | When fsync'ing files, fsync the parent directory in the case where we rename a file into place, or create a new file, to ensure that the directory entry is flushed correctly.
| * git_filebuf: optionally fsync when committingEdward Thomson2017-02-281-0/+8
| |
* | filebuf: fix resolving absolute symlinksSven Strickroth22017-03-201-1/+1
|/ | | | | The symlink destination is always concatenated to the original path. Fix this by using `git_buf_sets` instead of `git_buf_puts`.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-9/+9
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* filebuf: fix uninitialized warningEdward Thomson2016-06-011-1/+1
|
* filebuf: allow using a custom buffer sizeCarlos Martín Nieto2016-03-221-1/+6
| | | | | | Allow setting the buffer size on open in order to use this data structure more generally as a spill buffer, with larger buffer sizes for specific use-cases.
* filebuf: handle write error in `lock_file`Patrick Steinhardt2016-03-111-1/+6
| | | | | | When writing to a file with locking not check if writing the locked file actually succeeds. Fix the issue by returning error code and message when writing fails.
* filebuf: detect directories in our wayEdward Thomson2015-11-031-0/+6
| | | | | | When creating a filebuf, detect a directory that exists in our target file location. This prevents a failure later, when we try to move the lock file to the destination.
* filebuf: follow symlinks when creating a lock filecmn/follow-symlinkCarlos Martín Nieto2015-09-051-3/+81
| | | | | | | We create a lockfile to update files under GIT_DIR. Sometimes these files are actually located elsewhere and a symlink takes their place. In that case we should lock and update the file at its final location rather than overwrite the symlink.
* filebuf: remove lockfile upon rename errorscmn/filebuf-rename-errorCarlos Martín Nieto2015-07-241-1/+6
| | | | | | | | | | When we have an error renaming the lockfile, we need to make sure that we remove it upon cleanup. For this, we need to keep track of whether we opened the file and whether the rename succeeded. If we did create the lockfile but the rename did not succeed, we remove the lockfile. This won't protect against all errors, but the most common ones (target file is open) does get handled.
* centralizing all IO buffer size valuesJ Wyman2015-05-111-1/+1
|
* filebuf: use an int for return checkEdward Thomson2015-02-131-2/+2
|
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-6/+6
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* Use `size_t` to hold size of arraysEdward Thomson2015-02-121-6/+7
| | | | | | Use `size_t` to hold the size of arrays to ease overflow checking, lest we check for overflow of a `size_t` then promptly truncate by packing the length into a smaller type.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-2/+3
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* filebuf: make unlocking atomiccmn/filebuf-atomic-unlockCarlos Martín Nieto2014-06-041-2/+0
| | | | | | | | | | | | When renaming a lock file to its final location, we need to make sure that it is replaced atomically. We currently have a workaround for Windows by removing the target file. This means that the target file, which may be a ref or a packfile, may cease to exist for a short wile, which shold be avoided. Implement the workaround only in Windows, by making sure that the file we want to replace is writable.
* Remove now-duplicated stdarg.h includeEdward Thomson2014-02-241-2/+0
|
* move mode_t to filebuf_open instead of _commitEdward Thomson2013-11-041-20/+9
|
* Take umask into account in filebuf_commitEdward Thomson2013-11-041-1/+5
|
* index: report when it's lockedCarlos Martín Nieto2013-08-191-5/+5
| | | | | | | Report the index being locked with its own error code in order to be able to differentiate, as a locked index is typically the result of a crashed process or concurrent access, both of which often require user intervention to fix.
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* filebuf now has a git_hash_ctx instead of a ctx*Edward Thomson2012-11-131-17/+15
|
* Remove git_hash_ctx_new - callers now _ctx_init()Edward Thomson2012-11-131-4/+10
|
* Win32 CryptoAPI and CNG support for SHA1Edward Thomson2012-11-131-3/+3
|
* Add git_config_refresh() API to reload configRussell Belfer2012-10-301-0/+23
| | | | | | | | | | | | | | | | | | | | This adds a new API that allows users to reload the config if the file has changed on disk. A new config callback function to refresh the config was added. The modified time and file size are used to test if the file needs to be reloaded (and are now stored in the disk backend object). In writing tests, just using mtime was a problem / race, so I wanted to check file size as well. To support that, I extended `git_futils_readbuffer_updated` to optionally check file size in addition to mtime, and I added a new function `git_filebuf_stats` to fetch the mtime and size for an open filebuf (so that the config could be easily refreshed after a write). Lastly, I moved some similar file checking code for attributes into filebuf. It is still only being used for attrs, but it seems potentially reusable, so I thought I'd move it over.
* Properly handle p_readsVicent Marti2012-09-111-2/+7
|
* Fix valgrind warnings and spurious error messagesRussell Belfer2012-08-241-0/+1
| | | | | | Just clean up valgrind warnings about uninitialized memory and also clear out errno in some cases where it results in a false error message being generated at a later point.
* filebuf: Check the return value for `close`Vicent Marti2012-08-031-2/+7
|
* filebuf: add git_filebuf_flush()nulltoken2012-05-271-0/+5
|
* filebuf: add option not to buffer the contents at allCarlos Martín Nieto2012-04-131-2/+10
| | | | | The new indexer needs to be able to bypass any kind of buffering, as it's trying to map data that it has just written to disk.
* Convert attr, ignore, mwindow, status to new errorsRussell Belfer2012-03-161-1/+1
| | | | | Also cleaned up some previously converted code that still had little things to polish.
* Migrate ODB files to new error handlingRussell Belfer2012-03-121-2/+6
| | | | | | | | | | | | | | This migrates odb.c, odb_loose.c, odb_pack.c and pack.c to the new style of error handling. Also got the unix and win32 versions of map.c. There are some minor changes to other files but no others were completely converted. This also contains an update to filebuf so that a zeroed out filebuf will not think that the fd (== 0) is actually open (and inadvertently call close() on fd 0 if cleaned up). Lastly, this was built and tested on win32 and contains a bunch of fixes for the win32 build which was pretty broken.
* error-handling: On-disk config file backendVicent Martí2012-03-091-51/+99
| | | | | | | | | | | | | | | Includes: - Proper error reporting when encountering syntax errors in a config file (file, line number, column). - Rewritten `config_write`, now with 99% less goto-spaghetti - Error state in `git_filebuf`: filebuf write functions no longer need to be checked for error returns. If any of the writes performed on a buffer fail, the last call to `git_filebuf_commit` or `git_filebuf_hash` will fail accordingly and set the appropiate error message. Baller!
* Migrating diff to new error handlingRussell Belfer2012-03-061-2/+2
| | | | | | Ended up migrating a bunch of upstream functions as well including vector, attr_file, and odb in order to get this to work right.
* error-handling: ReferencesVicent Martí2012-03-061-43/+32
| | | | | Yes, this is error handling solely for `refs.c`, but some of the abstractions leak all ofer the code base.
* Ensure that commits don't fail if committing content that already existsPaul Betts2012-02-231-0/+2
| | | | | | | | | | | | | Making a commit that results in a blob that already exists in the ODB (i.e. committing something, then making a revert commit) will result in us trying to p_rename -> MoveFileExW a temp file into the existing ODB entry. Despite the MOVEFILE_REPLACE_EXISTING flag is passed in, Win32 does not care and fails it with STATUS_ACCESS_DENIED. To fix this, we p_unlink the ODB entry before attempting to rename it. This call will typically fail, but we don't care, we'll let the p_rename fail if the file actually does exist and we couldn't delete it for some reason (ACLs, etc).
* Update Copyright headerschu2012-02-131-1/+1
| | | | Signed-off-by: schu <schu-github@schulog.org>
* Move path related functions from fileops to pathRussell Belfer2012-01-171-3/+3
| | | | | | | | | | | This takes all of the functions that look up simple data about paths (such as `git_futils_isdir`) and moves them over to path.h (becoming `git_path_isdir`). This leaves fileops.h just with functions that actually manipulate the filesystem or look at the file contents in some way. As part of this, the dir.h header which is really just for win32 support was moved into win32 (with some minor changes).