summaryrefslogtreecommitdiff
path: root/src/filebuf.c
Commit message (Collapse)AuthorAgeFilesLines
* 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).
* Use git_buf for path storage instead of stack-based buffersRussell Belfer2011-12-071-3/+4
| | | | | | | | | | | | | | | | | | | | This converts virtually all of the places that allocate GIT_PATH_MAX buffers on the stack for manipulating paths to use git_buf objects instead. The patch is pretty careful not to touch the public API for libgit2, so there are a few places that still use GIT_PATH_MAX. This extends and changes some details of the git_buf implementation to add a couple of extra functions and to make error handling easier. This includes serious alterations to all the path.c functions, and several of the fileops.c ones, too. Also, there are a number of new functions that parallel existing ones except that use a git_buf instead of a stack-based buffer (such as git_config_find_global_r that exists alongsize git_config_find_global). This also modifies the win32 version of p_realpath to allocate whatever buffer size is needed to accommodate the realpath instead of hardcoding a GIT_PATH_MAX limit, but that change needs to be tested still.
* filebuf: add GIT_FILEBUF_INIT and protect multiple opens and cleanupsRussell Belfer2011-11-221-5/+17
| | | | | | | | Update all stack allocations of git_filebuf to use GIT_FILEBUF_INIT and make git_filebuf_open and git_filebuf_cleanup safe to be called multiple times on the same buffer. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Implement p_renameCarlos Martín Nieto2011-11-071-1/+1
| | | | | | Move the callers of git_futils_mv_atomic to use p_rename. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
* Merge pull request #456 from brodie/perm-fixesVicent Martí2011-10-281-5/+13
|\ | | | | Create objects, indexes, and directories with the right file permissions
| * *: correct and codify various file permissionsBrodie Rao2011-10-141-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following files now have 0444 permissions: - loose objects - pack indexes - pack files - packs downloaded by fetch - packs downloaded by the HTTP transport And the following files now have 0666 permissions: - config files - repository indexes - reflogs - refs This brings libgit2 more in line with Git. Note that git_filebuf_commit() and git_filebuf_commit_at() have both gained a new mode parameter. The latter change fixes an important issue where filebufs created with GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3) usage). Now we chmod() the file before renaming it into place. Tests have been added to confirm that new commit, tag, and tree objects are created with the right permissions. I don't have access to Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
| * fileops/repository: create (most) directories with 0777 permissionsBrodie Rao2011-10-141-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To further match how Git behaves, this change makes most of the directories libgit2 creates in a git repo have a file mode of 0777. Specifically: - Intermediate directories created with git_futils_mkpath2file() have 0777 permissions. This affects odb_loose, reflog, and refs. - The top level folder for bare repos is created with 0777 permissions. - The top level folder for non-bare repos is created with 0755 permissions. - /objects/info/, /objects/pack/, /refs/heads/, and /refs/tags/ are created with 0777 permissions. Additionally, the following changes have been made: - fileops functions that create intermediate directories have grown a new dirmode parameter. The only exception to this is filebuf's lock_file(), which unconditionally creates intermediate directories with 0777 permissions when GIT_FILEBUF_FORCE is set. - The test runner now sets the umask to 0 before running any tests. This ensurses all file mode checks are consistent across systems. - t09-tree.c now does a directory permissions check. I've avoided adding this check to other tests that might reuse existing directories from the prefabricated test repos. Because they're checked into the repo, they have 0755 permissions. - Other assorted directories created by tests have 0777 permissions.