summaryrefslogtreecommitdiff
path: root/src/filebuf.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* | global: Properly use `git__` memory wrappersVicent Marti2011-10-281-7/+7
|/ | | | | Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers.
* odb: Pass compression settings to filebufVicent Marti2011-09-291-4/+5
|
* Merge pull request #393 from schu/unused-but-set-variableVicent Martí2011-09-181-1/+2
|\ | | | | filebuf.c: fix unused-but-set warning
| * filebuf.c: fix unused-but-set warningschu2011-09-091-1/+2
| | | | | | | | | | | | | | | | write_deflate() used to ignore errors by zlib's deflate function when not compiling in DEBUG mode. Always read $result and throw an error instead. Signed-off-by: schu <schu-github@schulog.org>
* | Cleanup legal dataVicent Marti2011-09-191-21/+3
|/ | | | | | | | | | 1. The license header is technically not valid if it doesn't have a copyright signature. 2. The COPYING file has been updated with the different licenses used in the project. 3. The full GPLv2 header in each file annoys me.
* Add casts to get rid of some warnings when filling zlib structuresSebastian Schuberth2011-09-081-4/+4
|
* Get rid of a superfluous pointer castSebastian Schuberth2011-09-081-1/+1
|
* Fix minor indentation issues (spaces to tabs)Sebastian Schuberth2011-09-081-4/+4
|
* filebuf: update git_filebuf.write signature to take non-const bufferKirill A. Shutemov2011-07-251-18/+7
| | | | | | | | | | | z_stream.next_in is non-const. Although currently Zlib doesn't modify buffer content on deflate(), it might be change in the future. gzwrite() already modify it. To avoid this let's change signature of git_filebuf.write and rework git_filebuf_write() accordingly. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* odb: Direct writes are backVicent Marti2011-07-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | DIRECT WRITES ARE BACK AND FASTER THAN EVER. The streaming writer to the ODB was an overkill for the smaller objects like Commit and Tags; most of the streaming logic was taking too long. This commit makes Commits, Tags and Trees to be built-up in memory, and then written to disk in 2 pushes (header + data), instead of streaming everything. This is *always* faster, even for big files (since the git_filebuf class still does streaming writes when the memory cache overflows). This is also a gazillion lines of code smaller, because we don't have to precompute the final size of the object before starting the stream (this was kind of defeating the point of streaming, anyway). Blobs are still written with full streaming instead of loading them in memory, since this is still the fastest way. A new `git_buf` class has been added. It's missing some features, but it'll get there.
* posix: Portable `vsnprintf`Vicent Marti2011-07-091-12/+31
| | | | | | | | | | | | | | | Our good, lovely folks at Microsoft decided that there was no good reason to make `vsnprintf` compilant with the C standard, so that function in Windows returns -1 on overflow, instead of returning the actual byte count needed to write the full string. We now handle this situation more gracefully with the POSIX compatibility layer, by returning the needed byte size using an auxiliary method instead of blindly resizing the target buffer until it fits. This means we can now support `printf`s of any size by allocating a temporary buffer. That's good.
* fileops: CleanupVicent Marti2011-07-051-17/+17
| | | | | | | | | | | | | | | | Cleaned up the structure of the whole OS-abstraction layer. fileops.c now contains a set of utility methods for file management used by the library. These are abstractions on top of the original POSIX calls. There's a new file called `posix.c` that contains emulations/reimplementations of all the POSIX calls the library uses. These are prefixed with `p_`. There's a specific posix file for each platform (win32 and unix). All the path-related methods have been moved from `utils.c` to `path.c` and have their own prefix.
* cleanup: remove trailing spacesKirill A. Shutemov2011-07-011-1/+1
| | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* filebuf: fix endless loop on writing buf > WRITE_BUFFER_SIZEKirill A. Shutemov2011-06-301-0/+1
| | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* filebuf cleanup: only unlink lockfile if we've opened itCarlos Martín Nieto2011-06-071-1/+1
| | | | | | | | Add a check for the file descriptor in git_filebuf_cleanup. Without it, an existing lockfile would be deleted if we tried to acquire it (but failed, as the lockfile already existed). Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
* filebuf: Fix printf buffer overflowsVicent Marti2011-06-061-1/+6
| | | | | | | The filebuf was not being properly written after a flush. This should cut it now. Fixes #228