rugged 0.19.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +184 -33
- data/ext/rugged/extconf.rb +111 -28
- data/ext/rugged/rugged.c +327 -89
- data/ext/rugged/rugged.h +64 -28
- data/ext/rugged/rugged_allocator.c +89 -0
- data/ext/rugged/rugged_backend.c +17 -0
- data/ext/rugged/rugged_blame.c +278 -0
- data/ext/rugged/rugged_blob.c +301 -75
- data/ext/rugged/rugged_branch.c +92 -242
- data/ext/rugged/rugged_branch_collection.c +388 -0
- data/ext/rugged/rugged_commit.c +575 -79
- data/ext/rugged/rugged_config.c +129 -36
- data/ext/rugged/rugged_cred.c +131 -0
- data/ext/rugged/rugged_diff.c +291 -122
- data/ext/rugged/rugged_diff_delta.c +16 -22
- data/ext/rugged/rugged_diff_hunk.c +35 -51
- data/ext/rugged/rugged_diff_line.c +23 -36
- data/ext/rugged/rugged_index.c +289 -152
- data/ext/rugged/rugged_note.c +50 -60
- data/ext/rugged/rugged_object.c +13 -30
- data/ext/rugged/rugged_patch.c +400 -0
- data/ext/rugged/rugged_rebase.c +397 -0
- data/ext/rugged/rugged_reference.c +76 -346
- data/ext/rugged/rugged_reference_collection.c +423 -0
- data/ext/rugged/rugged_remote.c +438 -461
- data/ext/rugged/rugged_remote_collection.c +435 -0
- data/ext/rugged/rugged_repo.c +1548 -365
- data/ext/rugged/rugged_revwalk.c +378 -99
- data/ext/rugged/rugged_settings.c +86 -23
- data/ext/rugged/rugged_signature.c +47 -37
- data/ext/rugged/rugged_submodule.c +835 -0
- data/ext/rugged/rugged_submodule_collection.c +366 -0
- data/ext/rugged/rugged_tag.c +88 -210
- data/ext/rugged/rugged_tag_collection.c +326 -0
- data/ext/rugged/rugged_tree.c +460 -217
- data/lib/rugged/attributes.rb +46 -0
- data/lib/rugged/blob.rb +33 -0
- data/lib/rugged/branch.rb +12 -16
- data/lib/rugged/commit.rb +9 -0
- data/lib/rugged/console.rb +5 -0
- data/lib/rugged/credentials.rb +48 -0
- data/lib/rugged/diff/delta.rb +6 -2
- data/lib/rugged/diff/hunk.rb +9 -9
- data/lib/rugged/diff/line.rb +28 -5
- data/lib/rugged/diff.rb +7 -1
- data/lib/rugged/index.rb +120 -0
- data/lib/rugged/object.rb +5 -0
- data/lib/rugged/patch.rb +41 -0
- data/lib/rugged/reference.rb +6 -3
- data/lib/rugged/remote.rb +5 -9
- data/lib/rugged/repository.rb +126 -14
- data/lib/rugged/submodule_collection.rb +53 -0
- data/lib/rugged/tag.rb +45 -16
- data/lib/rugged/tree.rb +163 -1
- data/lib/rugged/version.rb +6 -1
- data/lib/rugged/walker.rb +5 -0
- data/lib/rugged.rb +16 -1
- data/vendor/libgit2/AUTHORS +77 -0
- data/vendor/libgit2/CMakeLists.txt +317 -0
- data/vendor/libgit2/COPYING +993 -0
- data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +30 -0
- data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
- data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
- data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +11 -0
- data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +26 -0
- data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
- data/vendor/libgit2/cmake/Modules/FindHTTP_Parser.cmake +39 -0
- data/vendor/libgit2/cmake/Modules/FindIconv.cmake +45 -0
- data/vendor/libgit2/cmake/Modules/FindPkgLibraries.cmake +28 -0
- data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +28 -0
- data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +20 -0
- data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
- data/vendor/libgit2/cmake/Modules/IdeSplitSources.cmake +22 -0
- data/vendor/libgit2/deps/http-parser/CMakeLists.txt +5 -0
- data/vendor/libgit2/deps/http-parser/COPYING +23 -0
- data/vendor/libgit2/deps/http-parser/http_parser.c +5 -2
- data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
- data/vendor/libgit2/deps/regex/CMakeLists.txt +2 -0
- data/vendor/libgit2/deps/regex/COPYING +502 -0
- data/vendor/libgit2/deps/regex/regex.c +10 -3
- data/vendor/libgit2/deps/winhttp/CMakeLists.txt +26 -0
- data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
- data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
- data/vendor/libgit2/deps/winhttp/urlmon.h +45 -0
- data/vendor/libgit2/deps/winhttp/winhttp.def +29 -0
- data/vendor/libgit2/deps/winhttp/winhttp.h +594 -0
- data/vendor/libgit2/deps/winhttp/winhttp64.def +29 -0
- data/vendor/libgit2/deps/zlib/CMakeLists.txt +5 -0
- data/vendor/libgit2/deps/zlib/COPYING +27 -0
- data/vendor/libgit2/deps/zlib/adler32.c +51 -34
- data/vendor/libgit2/deps/zlib/crc32.c +61 -61
- data/vendor/libgit2/deps/zlib/crc32.h +1 -1
- data/vendor/libgit2/deps/zlib/deflate.c +681 -352
- data/vendor/libgit2/deps/zlib/deflate.h +25 -18
- data/vendor/libgit2/deps/zlib/gzguts.h +218 -0
- data/vendor/libgit2/deps/zlib/infback.c +640 -0
- data/vendor/libgit2/deps/zlib/inffast.c +36 -53
- data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
- data/vendor/libgit2/deps/zlib/inflate.c +167 -86
- data/vendor/libgit2/deps/zlib/inflate.h +7 -4
- data/vendor/libgit2/deps/zlib/inftrees.c +24 -50
- data/vendor/libgit2/deps/zlib/trees.c +55 -96
- data/vendor/libgit2/deps/zlib/zconf.h +499 -19
- data/vendor/libgit2/deps/zlib/zlib.h +526 -227
- data/vendor/libgit2/deps/zlib/zutil.c +39 -32
- data/vendor/libgit2/deps/zlib/zutil.h +75 -78
- data/vendor/libgit2/include/git2/annotated_commit.h +125 -0
- data/vendor/libgit2/include/git2/apply.h +129 -0
- data/vendor/libgit2/include/git2/attr.h +36 -21
- data/vendor/libgit2/include/git2/blame.h +229 -0
- data/vendor/libgit2/include/git2/blob.h +81 -44
- data/vendor/libgit2/include/git2/branch.h +81 -42
- data/vendor/libgit2/include/git2/buffer.h +128 -0
- data/vendor/libgit2/include/git2/checkout.h +141 -67
- data/vendor/libgit2/include/git2/cherrypick.h +92 -0
- data/vendor/libgit2/include/git2/clone.h +157 -58
- data/vendor/libgit2/include/git2/commit.h +231 -12
- data/vendor/libgit2/include/git2/common.h +216 -30
- data/vendor/libgit2/include/git2/config.h +274 -48
- data/vendor/libgit2/include/git2/cred_helpers.h +4 -4
- data/vendor/libgit2/include/git2/deprecated.h +253 -0
- data/vendor/libgit2/include/git2/describe.h +189 -0
- data/vendor/libgit2/include/git2/diff.h +985 -575
- data/vendor/libgit2/include/git2/errors.h +93 -52
- data/vendor/libgit2/include/git2/filter.h +217 -0
- data/vendor/libgit2/include/git2/global.h +44 -0
- data/vendor/libgit2/include/git2/graph.h +17 -0
- data/vendor/libgit2/include/git2/ignore.h +2 -2
- data/vendor/libgit2/include/git2/index.h +269 -94
- data/vendor/libgit2/include/git2/indexer.h +44 -12
- data/vendor/libgit2/include/git2/mailmap.h +115 -0
- data/vendor/libgit2/include/git2/merge.h +501 -64
- data/vendor/libgit2/include/git2/message.h +52 -17
- data/vendor/libgit2/include/git2/net.h +11 -5
- data/vendor/libgit2/include/git2/notes.h +120 -16
- data/vendor/libgit2/include/git2/object.h +62 -23
- data/vendor/libgit2/include/git2/odb.h +140 -24
- data/vendor/libgit2/include/git2/odb_backend.h +56 -12
- data/vendor/libgit2/include/git2/oid.h +17 -18
- data/vendor/libgit2/include/git2/oidarray.h +40 -0
- data/vendor/libgit2/include/git2/pack.h +86 -7
- data/vendor/libgit2/include/git2/patch.h +274 -0
- data/vendor/libgit2/include/git2/pathspec.h +280 -0
- data/vendor/libgit2/include/git2/proxy.h +96 -0
- data/vendor/libgit2/include/git2/rebase.h +323 -0
- data/vendor/libgit2/include/git2/reflog.h +12 -9
- data/vendor/libgit2/include/git2/refs.h +241 -46
- data/vendor/libgit2/include/git2/refspec.h +20 -4
- data/vendor/libgit2/include/git2/remote.h +636 -209
- data/vendor/libgit2/include/git2/repository.h +267 -57
- data/vendor/libgit2/include/git2/reset.h +36 -6
- data/vendor/libgit2/include/git2/revert.h +91 -0
- data/vendor/libgit2/include/git2/revparse.h +27 -16
- data/vendor/libgit2/include/git2/revwalk.h +78 -35
- data/vendor/libgit2/include/git2/signature.h +32 -5
- data/vendor/libgit2/include/git2/stash.h +160 -21
- data/vendor/libgit2/include/git2/status.h +92 -30
- data/vendor/libgit2/include/git2/submodule.h +226 -133
- data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
- data/vendor/libgit2/include/git2/sys/commit.h +38 -4
- data/vendor/libgit2/include/git2/sys/config.h +68 -9
- data/vendor/libgit2/include/git2/sys/diff.h +94 -0
- data/vendor/libgit2/include/git2/sys/filter.h +332 -0
- data/vendor/libgit2/include/git2/sys/hashsig.h +106 -0
- data/vendor/libgit2/include/git2/sys/index.h +6 -5
- data/vendor/libgit2/include/git2/sys/mempack.h +86 -0
- data/vendor/libgit2/include/git2/sys/merge.h +182 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +66 -28
- data/vendor/libgit2/include/git2/sys/openssl.h +38 -0
- data/vendor/libgit2/include/git2/sys/path.h +64 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +79 -19
- data/vendor/libgit2/include/git2/sys/reflog.h +21 -0
- data/vendor/libgit2/include/git2/sys/refs.h +13 -2
- data/vendor/libgit2/include/git2/sys/repository.h +64 -1
- data/vendor/libgit2/include/git2/sys/stream.h +138 -0
- data/vendor/libgit2/include/git2/sys/time.h +31 -0
- data/vendor/libgit2/include/git2/sys/transport.h +439 -0
- data/vendor/libgit2/include/git2/tag.h +11 -2
- data/vendor/libgit2/include/git2/trace.h +1 -1
- data/vendor/libgit2/include/git2/transaction.h +121 -0
- data/vendor/libgit2/include/git2/transport.h +261 -292
- data/vendor/libgit2/include/git2/tree.h +111 -21
- data/vendor/libgit2/include/git2/types.h +244 -32
- data/vendor/libgit2/include/git2/version.h +5 -2
- data/vendor/libgit2/include/git2/worktree.h +255 -0
- data/vendor/libgit2/include/git2.h +50 -40
- data/vendor/libgit2/libgit2.pc.in +13 -0
- data/vendor/libgit2/src/CMakeLists.txt +525 -0
- data/vendor/libgit2/src/alloc.c +55 -0
- data/vendor/libgit2/src/alloc.h +40 -0
- data/vendor/libgit2/src/annotated_commit.c +228 -0
- data/vendor/libgit2/src/annotated_commit.h +52 -0
- data/vendor/libgit2/src/apply.c +855 -0
- data/vendor/libgit2/src/apply.h +25 -0
- data/vendor/libgit2/src/array.h +74 -16
- data/vendor/libgit2/src/attr.c +239 -408
- data/vendor/libgit2/src/attr.h +3 -33
- data/vendor/libgit2/src/attr_file.c +424 -156
- data/vendor/libgit2/src/attr_file.h +95 -23
- data/vendor/libgit2/src/attrcache.c +469 -0
- data/vendor/libgit2/src/attrcache.h +37 -5
- data/vendor/libgit2/src/bitvec.h +75 -0
- data/vendor/libgit2/src/blame.c +532 -0
- data/vendor/libgit2/src/blame.h +95 -0
- data/vendor/libgit2/src/blame_git.c +668 -0
- data/vendor/libgit2/src/blame_git.h +22 -0
- data/vendor/libgit2/src/blob.c +233 -129
- data/vendor/libgit2/src/blob.h +29 -1
- data/vendor/libgit2/src/branch.c +295 -197
- data/vendor/libgit2/src/branch.h +2 -0
- data/vendor/libgit2/src/buf_text.c +52 -27
- data/vendor/libgit2/src/buf_text.h +7 -7
- data/vendor/libgit2/src/buffer.c +609 -52
- data/vendor/libgit2/src/buffer.h +68 -23
- data/vendor/libgit2/src/cache.c +48 -51
- data/vendor/libgit2/src/cache.h +6 -4
- data/vendor/libgit2/src/cc-compat.h +35 -7
- data/vendor/libgit2/src/checkout.c +1827 -483
- data/vendor/libgit2/src/checkout.h +4 -1
- data/vendor/libgit2/src/cherrypick.c +230 -0
- data/vendor/libgit2/src/clone.c +338 -258
- data/vendor/libgit2/src/{compress.h → clone.h} +5 -5
- data/vendor/libgit2/src/commit.c +711 -124
- data/vendor/libgit2/src/commit.h +10 -3
- data/vendor/libgit2/src/commit_list.c +21 -14
- data/vendor/libgit2/src/commit_list.h +9 -3
- data/vendor/libgit2/src/common.h +153 -13
- data/vendor/libgit2/src/config.c +871 -242
- data/vendor/libgit2/src/config.h +58 -14
- data/vendor/libgit2/src/config_backend.h +84 -0
- data/vendor/libgit2/src/config_cache.c +44 -18
- data/vendor/libgit2/src/config_entries.c +259 -0
- data/vendor/libgit2/src/config_entries.h +23 -0
- data/vendor/libgit2/src/config_file.c +837 -1113
- data/vendor/libgit2/src/config_mem.c +224 -0
- data/vendor/libgit2/src/config_parse.c +558 -0
- data/vendor/libgit2/src/config_parse.h +64 -0
- data/vendor/libgit2/src/crlf.c +290 -195
- data/vendor/libgit2/src/date.c +35 -7
- data/vendor/libgit2/src/delta.c +275 -71
- data/vendor/libgit2/src/delta.h +80 -58
- data/vendor/libgit2/src/describe.c +893 -0
- data/vendor/libgit2/src/diff.c +330 -1128
- data/vendor/libgit2/src/diff.h +25 -67
- data/vendor/libgit2/src/diff_driver.c +225 -109
- data/vendor/libgit2/src/diff_driver.h +5 -2
- data/vendor/libgit2/src/diff_file.c +128 -103
- data/vendor/libgit2/src/diff_file.h +17 -12
- data/vendor/libgit2/src/diff_generate.c +1622 -0
- data/vendor/libgit2/src/diff_generate.h +128 -0
- data/vendor/libgit2/src/diff_parse.c +108 -0
- data/vendor/libgit2/src/diff_parse.h +20 -0
- data/vendor/libgit2/src/diff_print.c +578 -218
- data/vendor/libgit2/src/diff_stats.c +362 -0
- data/vendor/libgit2/src/diff_tform.c +429 -257
- data/vendor/libgit2/src/diff_tform.h +25 -0
- data/vendor/libgit2/src/diff_xdiff.c +143 -46
- data/vendor/libgit2/src/diff_xdiff.h +12 -5
- data/vendor/libgit2/src/errors.c +150 -34
- data/vendor/libgit2/src/features.h.in +37 -0
- data/vendor/libgit2/src/fetch.c +69 -46
- data/vendor/libgit2/src/fetch.h +6 -12
- data/vendor/libgit2/src/fetchhead.c +40 -33
- data/vendor/libgit2/src/fetchhead.h +5 -4
- data/vendor/libgit2/src/filebuf.c +163 -61
- data/vendor/libgit2/src/filebuf.h +13 -7
- data/vendor/libgit2/src/fileops.c +549 -407
- data/vendor/libgit2/src/fileops.h +97 -106
- data/vendor/libgit2/src/filter.c +989 -46
- data/vendor/libgit2/src/filter.h +21 -70
- data/vendor/libgit2/src/fnmatch.c +67 -11
- data/vendor/libgit2/src/fnmatch.h +27 -7
- data/vendor/libgit2/src/global.c +257 -63
- data/vendor/libgit2/src/global.h +19 -0
- data/vendor/libgit2/src/graph.c +39 -23
- data/vendor/libgit2/src/hash/hash_collisiondetect.h +51 -0
- data/vendor/libgit2/src/hash/hash_common_crypto.h +61 -0
- data/vendor/libgit2/src/hash/hash_generic.c +3 -3
- data/vendor/libgit2/src/hash/hash_generic.h +10 -5
- data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
- data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +26 -8
- data/vendor/libgit2/src/hash/hash_win32.c +71 -43
- data/vendor/libgit2/src/hash/hash_win32.h +4 -3
- data/vendor/libgit2/src/hash/sha1dc/sha1.c +1900 -0
- data/vendor/libgit2/src/hash/sha1dc/sha1.h +110 -0
- data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +372 -0
- data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +52 -0
- data/vendor/libgit2/src/hash.c +0 -1
- data/vendor/libgit2/src/hash.h +13 -6
- data/vendor/libgit2/src/hashsig.c +121 -126
- data/vendor/libgit2/src/ident.c +129 -0
- data/vendor/libgit2/src/idxmap.c +153 -0
- data/vendor/libgit2/src/idxmap.h +41 -0
- data/vendor/libgit2/src/ignore.c +362 -123
- data/vendor/libgit2/src/ignore.h +16 -4
- data/vendor/libgit2/src/index.c +2131 -692
- data/vendor/libgit2/src/index.h +138 -6
- data/vendor/libgit2/src/indexer.c +866 -266
- data/vendor/libgit2/src/indexer.h +16 -0
- data/vendor/libgit2/src/integer.h +106 -0
- data/vendor/libgit2/src/iterator.c +1888 -967
- data/vendor/libgit2/src/iterator.h +130 -67
- data/vendor/libgit2/src/khash.h +43 -29
- data/vendor/libgit2/src/mailmap.c +485 -0
- data/vendor/libgit2/src/mailmap.h +35 -0
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +1679 -479
- data/vendor/libgit2/src/merge.h +89 -22
- data/vendor/libgit2/src/merge_driver.c +426 -0
- data/vendor/libgit2/src/merge_driver.h +62 -0
- data/vendor/libgit2/src/merge_file.c +238 -101
- data/vendor/libgit2/src/message.c +4 -28
- data/vendor/libgit2/src/message.h +3 -1
- data/vendor/libgit2/src/mwindow.c +123 -15
- data/vendor/libgit2/src/mwindow.h +10 -1
- data/vendor/libgit2/src/netops.c +178 -499
- data/vendor/libgit2/src/netops.h +51 -27
- data/vendor/libgit2/src/notes.c +251 -94
- data/vendor/libgit2/src/notes.h +5 -2
- data/vendor/libgit2/src/object.c +253 -67
- data/vendor/libgit2/src/object.h +40 -2
- data/vendor/libgit2/src/object_api.c +30 -11
- data/vendor/libgit2/src/odb.c +765 -201
- data/vendor/libgit2/src/odb.h +40 -8
- data/vendor/libgit2/src/odb_loose.c +560 -346
- data/vendor/libgit2/src/odb_mempack.c +185 -0
- data/vendor/libgit2/src/odb_pack.c +117 -73
- data/vendor/libgit2/src/offmap.c +113 -0
- data/vendor/libgit2/src/offmap.h +32 -42
- data/vendor/libgit2/src/oid.c +45 -25
- data/vendor/libgit2/src/oid.h +26 -8
- data/vendor/libgit2/src/oidarray.c +34 -0
- data/vendor/libgit2/src/oidarray.h +20 -0
- data/vendor/libgit2/src/oidmap.c +125 -0
- data/vendor/libgit2/src/oidmap.h +30 -17
- data/vendor/libgit2/src/pack-objects.c +688 -265
- data/vendor/libgit2/src/pack-objects.h +27 -13
- data/vendor/libgit2/src/pack.c +418 -202
- data/vendor/libgit2/src/pack.h +25 -16
- data/vendor/libgit2/src/parse.c +124 -0
- data/vendor/libgit2/src/parse.h +61 -0
- data/vendor/libgit2/src/patch.c +223 -0
- data/vendor/libgit2/src/patch.h +68 -0
- data/vendor/libgit2/src/patch_generate.c +901 -0
- data/vendor/libgit2/src/patch_generate.h +69 -0
- data/vendor/libgit2/src/patch_parse.c +1136 -0
- data/vendor/libgit2/src/patch_parse.h +51 -0
- data/vendor/libgit2/src/path.c +1247 -241
- data/vendor/libgit2/src/path.h +353 -57
- data/vendor/libgit2/src/pathspec.c +586 -58
- data/vendor/libgit2/src/pathspec.h +37 -15
- data/vendor/libgit2/src/pool.c +134 -221
- data/vendor/libgit2/src/pool.h +38 -50
- data/vendor/libgit2/src/posix.c +76 -10
- data/vendor/libgit2/src/posix.h +74 -32
- data/vendor/libgit2/src/pqueue.c +79 -117
- data/vendor/libgit2/src/pqueue.h +38 -82
- data/vendor/libgit2/src/proxy.c +39 -0
- data/vendor/libgit2/src/proxy.h +17 -0
- data/vendor/libgit2/src/push.c +178 -279
- data/vendor/libgit2/src/push.h +93 -4
- data/vendor/libgit2/src/reader.c +265 -0
- data/vendor/libgit2/src/reader.h +107 -0
- data/vendor/libgit2/src/rebase.c +1364 -0
- data/vendor/libgit2/src/refdb.c +74 -19
- data/vendor/libgit2/src/refdb.h +16 -3
- data/vendor/libgit2/src/refdb_fs.c +1472 -603
- data/vendor/libgit2/src/refdb_fs.h +4 -0
- data/vendor/libgit2/src/reflog.c +40 -330
- data/vendor/libgit2/src/reflog.h +8 -2
- data/vendor/libgit2/src/refs.c +641 -225
- data/vendor/libgit2/src/refs.h +53 -6
- data/vendor/libgit2/src/refspec.c +175 -62
- data/vendor/libgit2/src/refspec.h +10 -25
- data/vendor/libgit2/src/remote.c +1741 -723
- data/vendor/libgit2/src/remote.h +17 -5
- data/vendor/libgit2/src/repository.c +1505 -421
- data/vendor/libgit2/src/repository.h +95 -15
- data/vendor/libgit2/src/reset.c +63 -26
- data/vendor/libgit2/src/revert.c +232 -0
- data/vendor/libgit2/src/revparse.c +94 -80
- data/vendor/libgit2/src/revwalk.c +427 -194
- data/vendor/libgit2/src/revwalk.h +14 -5
- data/vendor/libgit2/src/settings.c +290 -0
- data/vendor/libgit2/src/sha1_lookup.c +16 -159
- data/vendor/libgit2/src/sha1_lookup.h +5 -4
- data/vendor/libgit2/src/signature.c +138 -26
- data/vendor/libgit2/src/signature.h +5 -0
- data/vendor/libgit2/src/sortedcache.c +395 -0
- data/vendor/libgit2/src/sortedcache.h +180 -0
- data/vendor/libgit2/src/stash.c +629 -168
- data/vendor/libgit2/src/status.c +125 -75
- data/vendor/libgit2/src/status.h +4 -2
- data/vendor/libgit2/src/stdalloc.c +120 -0
- data/vendor/libgit2/src/stdalloc.h +17 -0
- data/vendor/libgit2/src/stream.h +86 -0
- data/vendor/libgit2/src/streams/mbedtls.c +483 -0
- data/vendor/libgit2/src/streams/mbedtls.h +23 -0
- data/vendor/libgit2/src/streams/openssl.c +789 -0
- data/vendor/libgit2/src/streams/openssl.h +23 -0
- data/vendor/libgit2/src/streams/registry.c +118 -0
- data/vendor/libgit2/src/streams/registry.h +19 -0
- data/vendor/libgit2/src/streams/socket.c +235 -0
- data/vendor/libgit2/src/streams/socket.h +23 -0
- data/vendor/libgit2/src/streams/stransport.c +323 -0
- data/vendor/libgit2/src/streams/stransport.h +21 -0
- data/vendor/libgit2/src/streams/tls.c +73 -0
- data/vendor/libgit2/src/streams/tls.h +31 -0
- data/vendor/libgit2/src/strmap.c +147 -0
- data/vendor/libgit2/src/strmap.h +46 -51
- data/vendor/libgit2/src/strnlen.h +24 -0
- data/vendor/libgit2/src/submodule.c +1633 -877
- data/vendor/libgit2/src/submodule.h +83 -21
- data/vendor/libgit2/src/sysdir.c +355 -0
- data/vendor/libgit2/src/sysdir.h +119 -0
- data/vendor/libgit2/src/tag.c +87 -62
- data/vendor/libgit2/src/tag.h +4 -1
- data/vendor/libgit2/src/thread-utils.c +3 -0
- data/vendor/libgit2/src/thread-utils.h +71 -35
- data/vendor/libgit2/src/trace.c +4 -4
- data/vendor/libgit2/src/trace.h +11 -3
- data/vendor/libgit2/src/trailer.c +416 -0
- data/vendor/libgit2/src/transaction.c +382 -0
- data/vendor/libgit2/src/transaction.h +14 -0
- data/vendor/libgit2/src/transport.c +133 -67
- data/vendor/libgit2/src/transports/auth.c +75 -0
- data/vendor/libgit2/src/transports/auth.h +64 -0
- data/vendor/libgit2/src/transports/auth_negotiate.c +277 -0
- data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
- data/vendor/libgit2/src/transports/cred.c +296 -68
- data/vendor/libgit2/src/transports/cred.h +16 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +4 -0
- data/vendor/libgit2/src/transports/git.c +108 -90
- data/vendor/libgit2/src/transports/http.c +803 -258
- data/vendor/libgit2/src/transports/http.h +25 -0
- data/vendor/libgit2/src/transports/local.c +265 -169
- data/vendor/libgit2/src/transports/smart.c +255 -45
- data/vendor/libgit2/src/transports/smart.h +42 -22
- data/vendor/libgit2/src/transports/smart_pkt.c +250 -159
- data/vendor/libgit2/src/transports/smart_protocol.c +414 -196
- data/vendor/libgit2/src/transports/ssh.c +645 -236
- data/vendor/libgit2/src/transports/ssh.h +14 -0
- data/vendor/libgit2/src/transports/winhttp.c +809 -353
- data/vendor/libgit2/src/tree-cache.c +138 -52
- data/vendor/libgit2/src/tree-cache.h +14 -7
- data/vendor/libgit2/src/tree.c +620 -259
- data/vendor/libgit2/src/tree.h +12 -19
- data/vendor/libgit2/src/tsort.c +3 -2
- data/vendor/libgit2/src/unix/map.c +25 -7
- data/vendor/libgit2/src/unix/posix.h +77 -12
- data/vendor/libgit2/src/unix/pthread.h +56 -0
- data/vendor/libgit2/src/unix/realpath.c +12 -8
- data/vendor/libgit2/src/userdiff.h +208 -0
- data/vendor/libgit2/src/util.c +349 -165
- data/vendor/libgit2/src/util.h +167 -85
- data/vendor/libgit2/src/varint.c +43 -0
- data/vendor/libgit2/src/varint.h +17 -0
- data/vendor/libgit2/src/vector.c +156 -33
- data/vendor/libgit2/src/vector.h +41 -5
- data/vendor/libgit2/src/win32/dir.c +22 -42
- data/vendor/libgit2/src/win32/dir.h +7 -5
- data/vendor/libgit2/src/win32/error.c +6 -32
- data/vendor/libgit2/src/win32/error.h +4 -2
- data/vendor/libgit2/src/win32/findfile.c +62 -69
- data/vendor/libgit2/src/win32/findfile.h +5 -13
- data/vendor/libgit2/src/win32/git2.rc +44 -0
- data/vendor/libgit2/src/win32/map.c +39 -11
- data/vendor/libgit2/src/win32/mingw-compat.h +10 -11
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -33
- data/vendor/libgit2/src/win32/path_w32.c +476 -0
- data/vendor/libgit2/src/win32/path_w32.h +104 -0
- data/vendor/libgit2/src/win32/posix.h +35 -30
- data/vendor/libgit2/src/win32/posix_w32.c +659 -327
- data/vendor/libgit2/src/win32/precompiled.h +7 -2
- data/vendor/libgit2/src/win32/reparse.h +57 -0
- data/vendor/libgit2/src/win32/thread.c +258 -0
- data/vendor/libgit2/src/win32/thread.h +64 -0
- data/vendor/libgit2/src/win32/utf-conv.c +127 -62
- data/vendor/libgit2/src/win32/utf-conv.h +47 -6
- data/vendor/libgit2/src/win32/version.h +21 -4
- data/vendor/libgit2/src/win32/w32_buffer.c +54 -0
- data/vendor/libgit2/src/win32/w32_buffer.h +20 -0
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +438 -0
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +129 -0
- data/vendor/libgit2/src/win32/w32_stack.c +193 -0
- data/vendor/libgit2/src/win32/w32_stack.h +140 -0
- data/vendor/libgit2/src/win32/w32_util.c +95 -0
- data/vendor/libgit2/src/win32/w32_util.h +170 -0
- data/vendor/libgit2/src/win32/win32-compat.h +52 -0
- data/vendor/libgit2/src/worktree.c +578 -0
- data/vendor/libgit2/src/worktree.h +39 -0
- data/vendor/libgit2/src/xdiff/xdiff.h +33 -18
- data/vendor/libgit2/src/xdiff/xdiffi.c +578 -88
- data/vendor/libgit2/src/xdiff/xdiffi.h +3 -2
- data/vendor/libgit2/src/xdiff/xemit.c +106 -45
- data/vendor/libgit2/src/xdiff/xemit.h +3 -3
- data/vendor/libgit2/src/xdiff/xhistogram.c +5 -4
- data/vendor/libgit2/src/xdiff/xinclude.h +3 -2
- data/vendor/libgit2/src/xdiff/xmacros.h +2 -2
- data/vendor/libgit2/src/xdiff/xmerge.c +167 -48
- data/vendor/libgit2/src/xdiff/xpatience.c +42 -10
- data/vendor/libgit2/src/xdiff/xprepare.c +14 -14
- data/vendor/libgit2/src/xdiff/xprepare.h +2 -2
- data/vendor/libgit2/src/xdiff/xtypes.h +2 -2
- data/vendor/libgit2/src/xdiff/xutils.c +60 -56
- data/vendor/libgit2/src/xdiff/xutils.h +3 -5
- data/vendor/libgit2/src/zstream.c +205 -0
- data/vendor/libgit2/src/zstream.h +53 -0
- metadata +281 -233
- data/Rakefile +0 -61
- data/ext/rugged/rugged_diff_patch.c +0 -169
- data/lib/rugged/diff/patch.rb +0 -28
- data/test/blob_test.rb +0 -341
- data/test/branch_test.rb +0 -199
- data/test/commit_test.rb +0 -104
- data/test/config_test.rb +0 -45
- data/test/coverage/cover.rb +0 -133
- data/test/diff_test.rb +0 -777
- data/test/errors_test.rb +0 -34
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +0 -1
- data/test/fixtures/attr/attr1 +0 -29
- data/test/fixtures/attr/attr2 +0 -21
- data/test/fixtures/attr/attr3 +0 -4
- data/test/fixtures/attr/binfile +0 -1
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +0 -1
- data/test/fixtures/attr/gitattributes +0 -29
- data/test/fixtures/attr/gitignore +0 -2
- data/test/fixtures/attr/ign +0 -1
- data/test/fixtures/attr/macro_bad +0 -1
- data/test/fixtures/attr/macro_test +0 -1
- data/test/fixtures/attr/root_test1 +0 -1
- data/test/fixtures/attr/root_test2 +0 -6
- data/test/fixtures/attr/root_test3 +0 -19
- data/test/fixtures/attr/root_test4.txt +0 -14
- data/test/fixtures/attr/sub/abc +0 -37
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +0 -1
- data/test/fixtures/attr/sub/ign/file +0 -1
- data/test/fixtures/attr/sub/ign/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/subsub.txt +0 -1
- data/test/fixtures/attr/sub/subdir_test1 +0 -2
- data/test/fixtures/attr/sub/subdir_test2.txt +0 -1
- data/test/fixtures/diff/another.txt +0 -38
- data/test/fixtures/diff/readme.txt +0 -36
- data/test/fixtures/mergedrepo/conflicts-one.txt +0 -5
- data/test/fixtures/mergedrepo/conflicts-two.txt +0 -5
- data/test/fixtures/mergedrepo/one.txt +0 -10
- data/test/fixtures/mergedrepo/two.txt +0 -12
- data/test/fixtures/status/current_file +0 -1
- data/test/fixtures/status/ignored_file +0 -1
- data/test/fixtures/status/modified_file +0 -2
- data/test/fixtures/status/new_file +0 -1
- data/test/fixtures/status/staged_changes +0 -2
- data/test/fixtures/status/staged_changes_modified_file +0 -3
- data/test/fixtures/status/staged_delete_modified_file +0 -1
- data/test/fixtures/status/staged_new_file +0 -1
- data/test/fixtures/status/staged_new_file_modified_file +0 -2
- data/test/fixtures/status/subdir/current_file +0 -1
- data/test/fixtures/status/subdir/modified_file +0 -2
- data/test/fixtures/status/subdir/new_file +0 -1
- data/test/fixtures/status/subdir.txt +0 -2
- data/test/fixtures/status//350/277/231 +0 -1
- data/test/fixtures/testrepo.git/HEAD +0 -1
- data/test/fixtures/testrepo.git/config +0 -13
- data/test/fixtures/testrepo.git/description +0 -1
- data/test/fixtures/testrepo.git/index +0 -0
- data/test/fixtures/testrepo.git/info/exclude +0 -6
- data/test/fixtures/testrepo.git/logs/HEAD +0 -3
- data/test/fixtures/testrepo.git/logs/refs/heads/master +0 -3
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d +0 -0
- data/test/fixtures/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 +0 -0
- data/test/fixtures/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 +0 -0
- data/test/fixtures/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd +0 -0
- data/test/fixtures/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2 +0 -0
- data/test/fixtures/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a +0 -2
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +0 -1
- data/test/fixtures/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 +0 -0
- data/test/fixtures/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 +0 -2
- data/test/fixtures/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 +0 -2
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +0 -1
- data/test/fixtures/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a +0 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d +0 -0
- data/test/fixtures/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 +0 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a +0 -3
- data/test/fixtures/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f +0 -2
- data/test/fixtures/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd +0 -0
- data/test/fixtures/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +0 -3
- data/test/fixtures/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 +0 -3
- data/test/fixtures/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd +0 -3
- data/test/fixtures/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b +0 -0
- data/test/fixtures/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 +0 -0
- data/test/fixtures/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 +0 -0
- data/test/fixtures/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack +0 -0
- data/test/fixtures/testrepo.git/packed-refs +0 -2
- data/test/fixtures/testrepo.git/refs/heads/master +0 -1
- data/test/fixtures/testrepo.git/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v0.9 +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v1.0 +0 -1
- data/test/fixtures/text_file.md +0 -464
- data/test/fixtures/unsymlinked.git/HEAD +0 -1
- data/test/fixtures/unsymlinked.git/config +0 -6
- data/test/fixtures/unsymlinked.git/description +0 -1
- data/test/fixtures/unsymlinked.git/info/exclude +0 -2
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +0 -2
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/master +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +0 -1
- data/test/index_test.rb +0 -333
- data/test/lib_test.rb +0 -127
- data/test/note_test.rb +0 -158
- data/test/object_test.rb +0 -43
- data/test/reference_test.rb +0 -207
- data/test/remote_test.rb +0 -324
- data/test/repo_pack_test.rb +0 -24
- data/test/repo_reset_test.rb +0 -82
- data/test/repo_test.rb +0 -402
- data/test/tag_test.rb +0 -68
- data/test/test_helper.rb +0 -92
- data/test/tree_test.rb +0 -91
- data/test/walker_test.rb +0 -88
- data/vendor/libgit2/Makefile.embed +0 -42
- data/vendor/libgit2/include/git2/push.h +0 -131
- data/vendor/libgit2/include/git2/threads.h +0 -50
- data/vendor/libgit2/src/amiga/map.c +0 -48
- data/vendor/libgit2/src/bswap.h +0 -97
- data/vendor/libgit2/src/compress.c +0 -53
- data/vendor/libgit2/src/config_file.h +0 -60
- data/vendor/libgit2/src/delta-apply.c +0 -134
- data/vendor/libgit2/src/delta-apply.h +0 -50
- data/vendor/libgit2/src/diff_patch.c +0 -995
- data/vendor/libgit2/src/diff_patch.h +0 -46
- data/vendor/libgit2/src/hashsig.h +0 -72
- data/vendor/libgit2/src/merge_file.h +0 -71
- data/vendor/libgit2/src/win32/pthread.c +0 -144
- data/vendor/libgit2/src/win32/pthread.h +0 -50
@@ -4,8 +4,11 @@
|
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
6
6
|
*/
|
7
|
-
|
7
|
+
|
8
8
|
#include "fileops.h"
|
9
|
+
|
10
|
+
#include "global.h"
|
11
|
+
#include "strmap.h"
|
9
12
|
#include <ctype.h>
|
10
13
|
#if GIT_WIN32
|
11
14
|
#include "win32/findfile.h"
|
@@ -14,13 +17,16 @@
|
|
14
17
|
int git_futils_mkpath2file(const char *file_path, const mode_t mode)
|
15
18
|
{
|
16
19
|
return git_futils_mkdir(
|
17
|
-
file_path,
|
20
|
+
file_path, mode,
|
18
21
|
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
|
19
22
|
}
|
20
23
|
|
21
|
-
int git_futils_mktmp(git_buf *path_out, const char *filename)
|
24
|
+
int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
|
22
25
|
{
|
23
26
|
int fd;
|
27
|
+
mode_t mask;
|
28
|
+
|
29
|
+
p_umask(mask = p_umask(0));
|
24
30
|
|
25
31
|
git_buf_sets(path_out, filename);
|
26
32
|
git_buf_puts(path_out, "_git2_XXXXXX");
|
@@ -29,8 +35,14 @@ int git_futils_mktmp(git_buf *path_out, const char *filename)
|
|
29
35
|
return -1;
|
30
36
|
|
31
37
|
if ((fd = p_mkstemp(path_out->ptr)) < 0) {
|
32
|
-
|
33
|
-
"
|
38
|
+
git_error_set(GIT_ERROR_OS,
|
39
|
+
"failed to create temporary file '%s'", path_out->ptr);
|
40
|
+
return -1;
|
41
|
+
}
|
42
|
+
|
43
|
+
if (p_chmod(path_out->ptr, (mode & ~mask))) {
|
44
|
+
git_error_set(GIT_ERROR_OS,
|
45
|
+
"failed to set permissions on file '%s'", path_out->ptr);
|
34
46
|
return -1;
|
35
47
|
}
|
36
48
|
|
@@ -46,7 +58,7 @@ int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode
|
|
46
58
|
|
47
59
|
fd = p_creat(path, mode);
|
48
60
|
if (fd < 0) {
|
49
|
-
|
61
|
+
git_error_set(GIT_ERROR_OS, "failed to create file '%s'", path);
|
50
62
|
return -1;
|
51
63
|
}
|
52
64
|
|
@@ -55,22 +67,20 @@ int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode
|
|
55
67
|
|
56
68
|
int git_futils_creat_locked(const char *path, const mode_t mode)
|
57
69
|
{
|
58
|
-
int fd
|
59
|
-
|
60
|
-
#ifdef GIT_WIN32
|
61
|
-
wchar_t buf[GIT_WIN_PATH];
|
62
|
-
|
63
|
-
git__utf8_to_16(buf, GIT_WIN_PATH, path);
|
64
|
-
fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC |
|
65
|
-
O_EXCL | O_BINARY | O_CLOEXEC, mode);
|
66
|
-
#else
|
67
|
-
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC |
|
68
|
-
O_EXCL | O_BINARY | O_CLOEXEC, mode);
|
69
|
-
#endif
|
70
|
+
int fd = p_open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC,
|
71
|
+
mode);
|
70
72
|
|
71
73
|
if (fd < 0) {
|
72
|
-
|
73
|
-
|
74
|
+
int error = errno;
|
75
|
+
git_error_set(GIT_ERROR_OS, "failed to create locked file '%s'", path);
|
76
|
+
switch (error) {
|
77
|
+
case EEXIST:
|
78
|
+
return GIT_ELOCKED;
|
79
|
+
case ENOENT:
|
80
|
+
return GIT_ENOTFOUND;
|
81
|
+
default:
|
82
|
+
return -1;
|
83
|
+
}
|
74
84
|
}
|
75
85
|
|
76
86
|
return fd;
|
@@ -87,20 +97,27 @@ int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, con
|
|
87
97
|
int git_futils_open_ro(const char *path)
|
88
98
|
{
|
89
99
|
int fd = p_open(path, O_RDONLY);
|
90
|
-
if (fd < 0)
|
91
|
-
|
92
|
-
fd = GIT_ENOTFOUND;
|
93
|
-
giterr_set(GITERR_OS, "Failed to open '%s'", path);
|
94
|
-
}
|
100
|
+
if (fd < 0)
|
101
|
+
return git_path_set_error(errno, path, "open");
|
95
102
|
return fd;
|
96
103
|
}
|
97
104
|
|
105
|
+
int git_futils_truncate(const char *path, int mode)
|
106
|
+
{
|
107
|
+
int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
|
108
|
+
if (fd < 0)
|
109
|
+
return git_path_set_error(errno, path, "open");
|
110
|
+
|
111
|
+
close(fd);
|
112
|
+
return 0;
|
113
|
+
}
|
114
|
+
|
98
115
|
git_off_t git_futils_filesize(git_file fd)
|
99
116
|
{
|
100
117
|
struct stat sb;
|
101
118
|
|
102
119
|
if (p_fstat(fd, &sb)) {
|
103
|
-
|
120
|
+
git_error_set(GIT_ERROR_OS, "failed to stat file descriptor");
|
104
121
|
return -1;
|
105
122
|
}
|
106
123
|
|
@@ -110,7 +127,7 @@ git_off_t git_futils_filesize(git_file fd)
|
|
110
127
|
mode_t git_futils_canonical_mode(mode_t raw_mode)
|
111
128
|
{
|
112
129
|
if (S_ISREG(raw_mode))
|
113
|
-
return S_IFREG |
|
130
|
+
return S_IFREG | GIT_PERMS_CANONICAL(raw_mode);
|
114
131
|
else if (S_ISLNK(raw_mode))
|
115
132
|
return S_IFLNK;
|
116
133
|
else if (S_ISGITLINK(raw_mode))
|
@@ -124,17 +141,25 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
|
|
124
141
|
int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
|
125
142
|
{
|
126
143
|
ssize_t read_size = 0;
|
144
|
+
size_t alloc_len;
|
127
145
|
|
128
146
|
git_buf_clear(buf);
|
129
147
|
|
130
|
-
if (
|
148
|
+
if (!git__is_ssizet(len)) {
|
149
|
+
git_error_set(GIT_ERROR_INVALID, "read too large");
|
150
|
+
return -1;
|
151
|
+
}
|
152
|
+
|
153
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
|
154
|
+
if (git_buf_grow(buf, alloc_len) < 0)
|
131
155
|
return -1;
|
132
156
|
|
133
157
|
/* p_read loops internally to read len bytes */
|
134
158
|
read_size = p_read(fd, buf->ptr, len);
|
135
159
|
|
136
160
|
if (read_size != (ssize_t)len) {
|
137
|
-
|
161
|
+
git_error_set(GIT_ERROR_OS, "failed to read descriptor");
|
162
|
+
git_buf_dispose(buf);
|
138
163
|
return -1;
|
139
164
|
}
|
140
165
|
|
@@ -145,87 +170,120 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
|
|
145
170
|
}
|
146
171
|
|
147
172
|
int git_futils_readbuffer_updated(
|
148
|
-
git_buf *
|
173
|
+
git_buf *out, const char *path, git_oid *checksum, int *updated)
|
149
174
|
{
|
175
|
+
int error;
|
150
176
|
git_file fd;
|
151
177
|
struct stat st;
|
152
|
-
|
178
|
+
git_buf buf = GIT_BUF_INIT;
|
179
|
+
git_oid checksum_new;
|
153
180
|
|
154
|
-
assert(
|
181
|
+
assert(out && path && *path);
|
155
182
|
|
156
183
|
if (updated != NULL)
|
157
184
|
*updated = 0;
|
158
185
|
|
159
|
-
if ((
|
160
|
-
return
|
186
|
+
if (p_stat(path, &st) < 0)
|
187
|
+
return git_path_set_error(errno, path, "stat");
|
161
188
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
return
|
189
|
+
|
190
|
+
if (S_ISDIR(st.st_mode)) {
|
191
|
+
git_error_set(GIT_ERROR_INVALID, "requested file is a directory");
|
192
|
+
return GIT_ENOTFOUND;
|
166
193
|
}
|
167
194
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
*/
|
172
|
-
if (size && *size != (size_t)st.st_size)
|
173
|
-
changed = true;
|
174
|
-
if (mtime && *mtime != st.st_mtime)
|
175
|
-
changed = true;
|
176
|
-
if (!size && !mtime)
|
177
|
-
changed = true;
|
178
|
-
|
179
|
-
if (!changed) {
|
180
|
-
p_close(fd);
|
181
|
-
return 0;
|
195
|
+
if (!git__is_sizet(st.st_size+1)) {
|
196
|
+
git_error_set(GIT_ERROR_OS, "invalid regular file stat for '%s'", path);
|
197
|
+
return -1;
|
182
198
|
}
|
183
199
|
|
184
|
-
if (
|
185
|
-
|
186
|
-
if (size != NULL)
|
187
|
-
*size = (size_t)st.st_size;
|
200
|
+
if ((fd = git_futils_open_ro(path)) < 0)
|
201
|
+
return fd;
|
188
202
|
|
189
|
-
if (git_futils_readbuffer_fd(buf, fd, (size_t)st.st_size) < 0) {
|
203
|
+
if (git_futils_readbuffer_fd(&buf, fd, (size_t)st.st_size) < 0) {
|
190
204
|
p_close(fd);
|
191
205
|
return -1;
|
192
206
|
}
|
193
207
|
|
194
208
|
p_close(fd);
|
195
209
|
|
210
|
+
if (checksum) {
|
211
|
+
if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
|
212
|
+
git_buf_dispose(&buf);
|
213
|
+
return error;
|
214
|
+
}
|
215
|
+
|
216
|
+
/*
|
217
|
+
* If we were given a checksum, we only want to use it if it's different
|
218
|
+
*/
|
219
|
+
if (!git_oid__cmp(checksum, &checksum_new)) {
|
220
|
+
git_buf_dispose(&buf);
|
221
|
+
if (updated)
|
222
|
+
*updated = 0;
|
223
|
+
|
224
|
+
return 0;
|
225
|
+
}
|
226
|
+
|
227
|
+
git_oid_cpy(checksum, &checksum_new);
|
228
|
+
}
|
229
|
+
|
230
|
+
/*
|
231
|
+
* If we're here, the file did change, or the user didn't have an old version
|
232
|
+
*/
|
196
233
|
if (updated != NULL)
|
197
234
|
*updated = 1;
|
198
235
|
|
236
|
+
git_buf_swap(out, &buf);
|
237
|
+
git_buf_dispose(&buf);
|
238
|
+
|
199
239
|
return 0;
|
200
240
|
}
|
201
241
|
|
202
242
|
int git_futils_readbuffer(git_buf *buf, const char *path)
|
203
243
|
{
|
204
|
-
return git_futils_readbuffer_updated(buf, path, NULL, NULL
|
244
|
+
return git_futils_readbuffer_updated(buf, path, NULL, NULL);
|
205
245
|
}
|
206
246
|
|
207
247
|
int git_futils_writebuffer(
|
208
248
|
const git_buf *buf, const char *path, int flags, mode_t mode)
|
209
249
|
{
|
210
|
-
int fd, error = 0;
|
250
|
+
int fd, do_fsync = 0, error = 0;
|
211
251
|
|
212
|
-
if (flags
|
252
|
+
if (!flags)
|
213
253
|
flags = O_CREAT | O_TRUNC | O_WRONLY;
|
254
|
+
|
255
|
+
if ((flags & O_FSYNC) != 0)
|
256
|
+
do_fsync = 1;
|
257
|
+
|
258
|
+
flags &= ~O_FSYNC;
|
259
|
+
|
214
260
|
if (!mode)
|
215
261
|
mode = GIT_FILEMODE_BLOB;
|
216
262
|
|
217
263
|
if ((fd = p_open(path, flags, mode)) < 0) {
|
218
|
-
|
264
|
+
git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path);
|
219
265
|
return fd;
|
220
266
|
}
|
221
267
|
|
222
268
|
if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
|
223
|
-
|
269
|
+
git_error_set(GIT_ERROR_OS, "could not write to '%s'", path);
|
224
270
|
(void)p_close(fd);
|
271
|
+
return error;
|
225
272
|
}
|
226
273
|
|
227
|
-
if ((error =
|
228
|
-
|
274
|
+
if (do_fsync && (error = p_fsync(fd)) < 0) {
|
275
|
+
git_error_set(GIT_ERROR_OS, "could not fsync '%s'", path);
|
276
|
+
p_close(fd);
|
277
|
+
return error;
|
278
|
+
}
|
279
|
+
|
280
|
+
if ((error = p_close(fd)) < 0) {
|
281
|
+
git_error_set(GIT_ERROR_OS, "error while closing '%s'", path);
|
282
|
+
return error;
|
283
|
+
}
|
284
|
+
|
285
|
+
if (do_fsync && (flags & O_CREAT))
|
286
|
+
error = git_futils_fsync_parent(path);
|
229
287
|
|
230
288
|
return error;
|
231
289
|
}
|
@@ -236,7 +294,7 @@ int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmod
|
|
236
294
|
return -1;
|
237
295
|
|
238
296
|
if (p_rename(from, to) < 0) {
|
239
|
-
|
297
|
+
git_error_set(GIT_ERROR_OS, "failed to rename '%s' to '%s'", from, to);
|
240
298
|
return -1;
|
241
299
|
}
|
242
300
|
|
@@ -257,13 +315,19 @@ int git_futils_mmap_ro_file(git_map *out, const char *path)
|
|
257
315
|
if (fd < 0)
|
258
316
|
return fd;
|
259
317
|
|
260
|
-
len = git_futils_filesize(fd)
|
318
|
+
if ((len = git_futils_filesize(fd)) < 0) {
|
319
|
+
result = -1;
|
320
|
+
goto out;
|
321
|
+
}
|
322
|
+
|
261
323
|
if (!git__is_sizet(len)) {
|
262
|
-
|
263
|
-
|
324
|
+
git_error_set(GIT_ERROR_OS, "file `%s` too large to mmap", path);
|
325
|
+
result = -1;
|
326
|
+
goto out;
|
264
327
|
}
|
265
328
|
|
266
329
|
result = git_futils_mmap_ro(out, fd, 0, (size_t)len);
|
330
|
+
out:
|
267
331
|
p_close(fd);
|
268
332
|
return result;
|
269
333
|
}
|
@@ -273,47 +337,230 @@ void git_futils_mmap_free(git_map *out)
|
|
273
337
|
p_munmap(out);
|
274
338
|
}
|
275
339
|
|
276
|
-
int
|
340
|
+
GIT_INLINE(int) mkdir_validate_dir(
|
277
341
|
const char *path,
|
278
|
-
|
342
|
+
struct stat *st,
|
279
343
|
mode_t mode,
|
280
|
-
uint32_t flags
|
344
|
+
uint32_t flags,
|
345
|
+
struct git_futils_mkdir_options *opts)
|
281
346
|
{
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
347
|
+
/* with exclusive create, existing dir is an error */
|
348
|
+
if ((flags & GIT_MKDIR_EXCL) != 0) {
|
349
|
+
git_error_set(GIT_ERROR_FILESYSTEM,
|
350
|
+
"failed to make directory '%s': directory exists", path);
|
351
|
+
return GIT_EEXISTS;
|
352
|
+
}
|
287
353
|
|
288
|
-
|
289
|
-
|
290
|
-
|
354
|
+
if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
|
355
|
+
(S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) {
|
356
|
+
if (p_unlink(path) < 0) {
|
357
|
+
git_error_set(GIT_ERROR_OS, "failed to remove %s '%s'",
|
358
|
+
S_ISLNK(st->st_mode) ? "symlink" : "file", path);
|
359
|
+
return GIT_EEXISTS;
|
360
|
+
}
|
291
361
|
|
292
|
-
|
293
|
-
|
294
|
-
|
362
|
+
opts->perfdata.mkdir_calls++;
|
363
|
+
|
364
|
+
if (p_mkdir(path, mode) < 0) {
|
365
|
+
git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path);
|
366
|
+
return GIT_EEXISTS;
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
else if (S_ISLNK(st->st_mode)) {
|
371
|
+
/* Re-stat the target, make sure it's a directory */
|
372
|
+
opts->perfdata.stat_calls++;
|
373
|
+
|
374
|
+
if (p_stat(path, st) < 0) {
|
375
|
+
git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path);
|
376
|
+
return GIT_EEXISTS;
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
else if (!S_ISDIR(st->st_mode)) {
|
381
|
+
git_error_set(GIT_ERROR_FILESYSTEM,
|
382
|
+
"failed to make directory '%s': directory exists", path);
|
383
|
+
return GIT_EEXISTS;
|
384
|
+
}
|
385
|
+
|
386
|
+
return 0;
|
387
|
+
}
|
388
|
+
|
389
|
+
GIT_INLINE(int) mkdir_validate_mode(
|
390
|
+
const char *path,
|
391
|
+
struct stat *st,
|
392
|
+
bool terminal_path,
|
393
|
+
mode_t mode,
|
394
|
+
uint32_t flags,
|
395
|
+
struct git_futils_mkdir_options *opts)
|
396
|
+
{
|
397
|
+
if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
|
398
|
+
(flags & GIT_MKDIR_CHMOD_PATH) != 0) && st->st_mode != mode) {
|
399
|
+
|
400
|
+
opts->perfdata.chmod_calls++;
|
401
|
+
|
402
|
+
if (p_chmod(path, mode) < 0) {
|
403
|
+
git_error_set(GIT_ERROR_OS, "failed to set permissions on '%s'", path);
|
404
|
+
return -1;
|
405
|
+
}
|
295
406
|
}
|
296
407
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
408
|
+
return 0;
|
409
|
+
}
|
410
|
+
|
411
|
+
GIT_INLINE(int) mkdir_canonicalize(
|
412
|
+
git_buf *path,
|
413
|
+
uint32_t flags)
|
414
|
+
{
|
415
|
+
ssize_t root_len;
|
416
|
+
|
417
|
+
if (path->size == 0) {
|
418
|
+
git_error_set(GIT_ERROR_OS, "attempt to create empty path");
|
419
|
+
return -1;
|
301
420
|
}
|
302
421
|
|
422
|
+
/* Trim trailing slashes (except the root) */
|
423
|
+
if ((root_len = git_path_root(path->ptr)) < 0)
|
424
|
+
root_len = 0;
|
425
|
+
else
|
426
|
+
root_len++;
|
427
|
+
|
428
|
+
while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/')
|
429
|
+
path->ptr[--path->size] = '\0';
|
430
|
+
|
303
431
|
/* if we are not supposed to made the last element, truncate it */
|
304
432
|
if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
|
305
|
-
|
433
|
+
git_path_dirname_r(path, path->ptr);
|
306
434
|
flags |= GIT_MKDIR_SKIP_LAST;
|
307
435
|
}
|
308
|
-
if ((flags & GIT_MKDIR_SKIP_LAST) != 0)
|
309
|
-
|
436
|
+
if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
|
437
|
+
git_path_dirname_r(path, path->ptr);
|
438
|
+
}
|
439
|
+
|
440
|
+
/* We were either given the root path (or trimmed it to
|
441
|
+
* the root), we don't have anything to do.
|
442
|
+
*/
|
443
|
+
if (path->size <= (size_t)root_len)
|
444
|
+
git_buf_clear(path);
|
445
|
+
|
446
|
+
return 0;
|
447
|
+
}
|
448
|
+
|
449
|
+
int git_futils_mkdir(
|
450
|
+
const char *path,
|
451
|
+
mode_t mode,
|
452
|
+
uint32_t flags)
|
453
|
+
{
|
454
|
+
git_buf make_path = GIT_BUF_INIT, parent_path = GIT_BUF_INIT;
|
455
|
+
const char *relative;
|
456
|
+
struct git_futils_mkdir_options opts = { 0 };
|
457
|
+
struct stat st;
|
458
|
+
size_t depth = 0;
|
459
|
+
int len = 0, root_len, error;
|
460
|
+
|
461
|
+
if ((error = git_buf_puts(&make_path, path)) < 0 ||
|
462
|
+
(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
|
463
|
+
(error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
|
464
|
+
make_path.size == 0)
|
465
|
+
goto done;
|
466
|
+
|
467
|
+
root_len = git_path_root(make_path.ptr);
|
468
|
+
|
469
|
+
/* find the first parent directory that exists. this will be used
|
470
|
+
* as the base to dirname_relative.
|
471
|
+
*/
|
472
|
+
for (relative = make_path.ptr; parent_path.size; ) {
|
473
|
+
error = p_lstat(parent_path.ptr, &st);
|
474
|
+
|
475
|
+
if (error == 0) {
|
476
|
+
break;
|
477
|
+
} else if (errno != ENOENT) {
|
478
|
+
git_error_set(GIT_ERROR_OS, "failed to stat '%s'", parent_path.ptr);
|
479
|
+
goto done;
|
480
|
+
}
|
481
|
+
|
482
|
+
depth++;
|
483
|
+
|
484
|
+
/* examine the parent of the current path */
|
485
|
+
if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
|
486
|
+
error = len;
|
487
|
+
goto done;
|
488
|
+
}
|
489
|
+
|
490
|
+
assert(len);
|
491
|
+
|
492
|
+
/* we've walked all the given path's parents and it's either relative
|
493
|
+
* or rooted. either way, give up and make the entire path.
|
494
|
+
*/
|
495
|
+
if ((len == 1 && parent_path.ptr[0] == '.') || len == root_len+1) {
|
496
|
+
relative = make_path.ptr;
|
497
|
+
break;
|
498
|
+
}
|
499
|
+
|
500
|
+
relative = make_path.ptr + len + 1;
|
501
|
+
|
502
|
+
/* not recursive? just make this directory relative to its parent. */
|
503
|
+
if ((flags & GIT_MKDIR_PATH) == 0)
|
504
|
+
break;
|
505
|
+
}
|
506
|
+
|
507
|
+
/* we found an item at the location we're trying to create,
|
508
|
+
* validate it.
|
509
|
+
*/
|
510
|
+
if (depth == 0) {
|
511
|
+
error = mkdir_validate_dir(make_path.ptr, &st, mode, flags, &opts);
|
512
|
+
|
513
|
+
if (!error)
|
514
|
+
error = mkdir_validate_mode(
|
515
|
+
make_path.ptr, &st, true, mode, flags, &opts);
|
310
516
|
|
311
|
-
/* if nothing left after truncation, then we're done! */
|
312
|
-
if (!make_path.size) {
|
313
|
-
error = 0;
|
314
517
|
goto done;
|
315
518
|
}
|
316
519
|
|
520
|
+
/* we already took `SKIP_LAST` and `SKIP_LAST2` into account when
|
521
|
+
* canonicalizing `make_path`.
|
522
|
+
*/
|
523
|
+
flags &= ~(GIT_MKDIR_SKIP_LAST2 | GIT_MKDIR_SKIP_LAST);
|
524
|
+
|
525
|
+
error = git_futils_mkdir_relative(relative,
|
526
|
+
parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
|
527
|
+
|
528
|
+
done:
|
529
|
+
git_buf_dispose(&make_path);
|
530
|
+
git_buf_dispose(&parent_path);
|
531
|
+
return error;
|
532
|
+
}
|
533
|
+
|
534
|
+
int git_futils_mkdir_r(const char *path, const mode_t mode)
|
535
|
+
{
|
536
|
+
return git_futils_mkdir(path, mode, GIT_MKDIR_PATH);
|
537
|
+
}
|
538
|
+
|
539
|
+
int git_futils_mkdir_relative(
|
540
|
+
const char *relative_path,
|
541
|
+
const char *base,
|
542
|
+
mode_t mode,
|
543
|
+
uint32_t flags,
|
544
|
+
struct git_futils_mkdir_options *opts)
|
545
|
+
{
|
546
|
+
git_buf make_path = GIT_BUF_INIT;
|
547
|
+
ssize_t root = 0, min_root_len;
|
548
|
+
char lastch = '/', *tail;
|
549
|
+
struct stat st;
|
550
|
+
struct git_futils_mkdir_options empty_opts = {0};
|
551
|
+
int error;
|
552
|
+
|
553
|
+
if (!opts)
|
554
|
+
opts = &empty_opts;
|
555
|
+
|
556
|
+
/* build path and find "root" where we should start calling mkdir */
|
557
|
+
if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
|
558
|
+
return -1;
|
559
|
+
|
560
|
+
if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
|
561
|
+
make_path.size == 0)
|
562
|
+
goto done;
|
563
|
+
|
317
564
|
/* if we are not supposed to make the whole path, reset root */
|
318
565
|
if ((flags & GIT_MKDIR_PATH) == 0)
|
319
566
|
root = git_buf_rfind(&make_path, '/');
|
@@ -333,6 +580,7 @@ int git_futils_mkdir(
|
|
333
580
|
|
334
581
|
/* walk down tail of path making each directory */
|
335
582
|
for (tail = &make_path.ptr[root]; *tail; *tail = lastch) {
|
583
|
+
bool mkdir_attempted = false;
|
336
584
|
|
337
585
|
/* advance tail to include next path component */
|
338
586
|
while (*tail == '/')
|
@@ -345,32 +593,56 @@ int git_futils_mkdir(
|
|
345
593
|
*tail = '\0';
|
346
594
|
st.st_mode = 0;
|
347
595
|
|
348
|
-
|
349
|
-
|
350
|
-
int tmp_errno = errno;
|
596
|
+
if (opts->dir_map && git_strmap_exists(opts->dir_map, make_path.ptr))
|
597
|
+
continue;
|
351
598
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
599
|
+
/* See what's going on with this path component */
|
600
|
+
opts->perfdata.stat_calls++;
|
601
|
+
|
602
|
+
retry_lstat:
|
603
|
+
if (p_lstat(make_path.ptr, &st) < 0) {
|
604
|
+
if (mkdir_attempted || errno != ENOENT) {
|
605
|
+
git_error_set(GIT_ERROR_OS, "cannot access component in path '%s'", make_path.ptr);
|
606
|
+
error = -1;
|
356
607
|
goto done;
|
357
608
|
}
|
358
609
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
610
|
+
git_error_clear();
|
611
|
+
opts->perfdata.mkdir_calls++;
|
612
|
+
mkdir_attempted = true;
|
613
|
+
if (p_mkdir(make_path.ptr, mode) < 0) {
|
614
|
+
if (errno == EEXIST)
|
615
|
+
goto retry_lstat;
|
616
|
+
git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", make_path.ptr);
|
617
|
+
error = -1;
|
363
618
|
goto done;
|
364
619
|
}
|
620
|
+
} else {
|
621
|
+
if ((error = mkdir_validate_dir(
|
622
|
+
make_path.ptr, &st, mode, flags, opts)) < 0)
|
623
|
+
goto done;
|
365
624
|
}
|
366
625
|
|
367
626
|
/* chmod if requested and necessary */
|
368
|
-
if ((
|
369
|
-
|
370
|
-
st.st_mode != mode &&
|
371
|
-
(error = p_chmod(make_path.ptr, mode)) < 0) {
|
372
|
-
giterr_set(GITERR_OS, "Failed to set permissions on '%s'", make_path.ptr);
|
627
|
+
if ((error = mkdir_validate_mode(
|
628
|
+
make_path.ptr, &st, (lastch == '\0'), mode, flags, opts)) < 0)
|
373
629
|
goto done;
|
630
|
+
|
631
|
+
if (opts->dir_map && opts->pool) {
|
632
|
+
char *cache_path;
|
633
|
+
size_t alloc_size;
|
634
|
+
|
635
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1);
|
636
|
+
if (!git__is_uint32(alloc_size))
|
637
|
+
return -1;
|
638
|
+
cache_path = git_pool_malloc(opts->pool, (uint32_t)alloc_size);
|
639
|
+
GIT_ERROR_CHECK_ALLOC(cache_path);
|
640
|
+
|
641
|
+
memcpy(cache_path, make_path.ptr, make_path.size + 1);
|
642
|
+
|
643
|
+
git_strmap_insert(opts->dir_map, cache_path, cache_path, &error);
|
644
|
+
if (error < 0)
|
645
|
+
goto done;
|
374
646
|
}
|
375
647
|
}
|
376
648
|
|
@@ -378,36 +650,37 @@ int git_futils_mkdir(
|
|
378
650
|
|
379
651
|
/* check that full path really is a directory if requested & needed */
|
380
652
|
if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 &&
|
381
|
-
lastch != '\0'
|
382
|
-
|
383
|
-
|
384
|
-
|
653
|
+
lastch != '\0') {
|
654
|
+
opts->perfdata.stat_calls++;
|
655
|
+
|
656
|
+
if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
|
657
|
+
git_error_set(GIT_ERROR_OS, "path is not a directory '%s'",
|
658
|
+
make_path.ptr);
|
659
|
+
error = GIT_ENOTFOUND;
|
660
|
+
}
|
385
661
|
}
|
386
662
|
|
387
663
|
done:
|
388
|
-
|
664
|
+
git_buf_dispose(&make_path);
|
389
665
|
return error;
|
390
666
|
}
|
391
667
|
|
392
|
-
int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode)
|
393
|
-
{
|
394
|
-
return git_futils_mkdir(path, base, mode, GIT_MKDIR_PATH);
|
395
|
-
}
|
396
|
-
|
397
668
|
typedef struct {
|
398
669
|
const char *base;
|
399
670
|
size_t baselen;
|
400
671
|
uint32_t flags;
|
401
|
-
int
|
672
|
+
int depth;
|
402
673
|
} futils__rmdir_data;
|
403
674
|
|
675
|
+
#define FUTILS_MAX_DEPTH 100
|
676
|
+
|
404
677
|
static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
|
405
678
|
{
|
406
679
|
if (filemsg)
|
407
|
-
|
680
|
+
git_error_set(GIT_ERROR_OS, "could not remove directory '%s': %s",
|
408
681
|
path, filemsg);
|
409
682
|
else
|
410
|
-
|
683
|
+
git_error_set(GIT_ERROR_OS, "could not remove directory '%s'", path);
|
411
684
|
|
412
685
|
return -1;
|
413
686
|
}
|
@@ -439,74 +712,82 @@ static int futils__rm_first_parent(git_buf *path, const char *ceiling)
|
|
439
712
|
|
440
713
|
static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
|
441
714
|
{
|
442
|
-
|
715
|
+
int error = 0;
|
443
716
|
futils__rmdir_data *data = opaque;
|
717
|
+
struct stat st;
|
718
|
+
|
719
|
+
if (data->depth > FUTILS_MAX_DEPTH)
|
720
|
+
error = futils__error_cannot_rmdir(
|
721
|
+
path->ptr, "directory nesting too deep");
|
444
722
|
|
445
|
-
if ((
|
723
|
+
else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) {
|
446
724
|
if (errno == ENOENT)
|
447
|
-
|
725
|
+
error = 0;
|
448
726
|
else if (errno == ENOTDIR) {
|
449
727
|
/* asked to remove a/b/c/d/e and a/b is a normal file */
|
450
728
|
if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0)
|
451
|
-
|
729
|
+
error = futils__rm_first_parent(path, data->base);
|
452
730
|
else
|
453
731
|
futils__error_cannot_rmdir(
|
454
732
|
path->ptr, "parent is not directory");
|
455
733
|
}
|
456
734
|
else
|
457
|
-
|
735
|
+
error = git_path_set_error(errno, path->ptr, "rmdir");
|
458
736
|
}
|
459
737
|
|
460
738
|
else if (S_ISDIR(st.st_mode)) {
|
461
|
-
|
739
|
+
data->depth++;
|
740
|
+
|
741
|
+
error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
|
742
|
+
|
743
|
+
data->depth--;
|
744
|
+
|
462
745
|
if (error < 0)
|
463
|
-
return
|
746
|
+
return error;
|
464
747
|
|
465
|
-
data->
|
748
|
+
if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
|
749
|
+
return error;
|
466
750
|
|
467
|
-
if (
|
751
|
+
if ((error = p_rmdir(path->ptr)) < 0) {
|
468
752
|
if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 &&
|
469
753
|
(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
|
470
|
-
|
754
|
+
error = 0;
|
471
755
|
else
|
472
|
-
|
756
|
+
error = git_path_set_error(errno, path->ptr, "rmdir");
|
473
757
|
}
|
474
758
|
}
|
475
759
|
|
476
760
|
else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
|
477
|
-
|
478
|
-
|
479
|
-
if (data->error < 0)
|
480
|
-
futils__error_cannot_rmdir(path->ptr, "cannot be removed");
|
761
|
+
if (p_unlink(path->ptr) < 0)
|
762
|
+
error = git_path_set_error(errno, path->ptr, "remove");
|
481
763
|
}
|
482
764
|
|
483
765
|
else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
|
484
|
-
|
766
|
+
error = futils__error_cannot_rmdir(path->ptr, "still present");
|
485
767
|
|
486
|
-
return
|
768
|
+
return error;
|
487
769
|
}
|
488
770
|
|
489
|
-
static int futils__rmdir_empty_parent(void *opaque,
|
771
|
+
static int futils__rmdir_empty_parent(void *opaque, const char *path)
|
490
772
|
{
|
491
773
|
futils__rmdir_data *data = opaque;
|
492
|
-
int error;
|
493
|
-
|
494
|
-
if (git_buf_len(path) <= data->baselen)
|
495
|
-
return GIT_ITEROVER;
|
774
|
+
int error = 0;
|
496
775
|
|
497
|
-
|
776
|
+
if (strlen(path) <= data->baselen)
|
777
|
+
error = GIT_ITEROVER;
|
498
778
|
|
499
|
-
if (
|
779
|
+
else if (p_rmdir(path) < 0) {
|
500
780
|
int en = errno;
|
501
781
|
|
502
782
|
if (en == ENOENT || en == ENOTDIR) {
|
503
|
-
|
504
|
-
|
783
|
+
/* do nothing */
|
784
|
+
} else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
|
785
|
+
en == EBUSY) {
|
786
|
+
error = git_path_set_error(errno, path, "rmdir");
|
505
787
|
} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
|
506
|
-
giterr_clear();
|
507
788
|
error = GIT_ITEROVER;
|
508
789
|
} else {
|
509
|
-
|
790
|
+
error = git_path_set_error(errno, path, "rmdir");
|
510
791
|
}
|
511
792
|
}
|
512
793
|
|
@@ -524,244 +805,28 @@ int git_futils_rmdir_r(
|
|
524
805
|
if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
|
525
806
|
return -1;
|
526
807
|
|
808
|
+
memset(&data, 0, sizeof(data));
|
527
809
|
data.base = base ? base : "";
|
528
810
|
data.baselen = base ? strlen(base) : 0;
|
529
811
|
data.flags = flags;
|
530
|
-
data.error = 0;
|
531
812
|
|
532
813
|
error = futils__rmdir_recurs_foreach(&data, &fullpath);
|
533
814
|
|
534
815
|
/* remove now-empty parents if requested */
|
535
|
-
if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
|
816
|
+
if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
|
536
817
|
error = git_path_walk_up(
|
537
818
|
&fullpath, base, futils__rmdir_empty_parent, &data);
|
538
819
|
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
git_buf_free(&fullpath);
|
544
|
-
|
545
|
-
return error;
|
546
|
-
}
|
547
|
-
|
548
|
-
int git_futils_cleanupdir_r(const char *path)
|
549
|
-
{
|
550
|
-
int error;
|
551
|
-
git_buf fullpath = GIT_BUF_INIT;
|
552
|
-
futils__rmdir_data data;
|
553
|
-
|
554
|
-
if ((error = git_buf_put(&fullpath, path, strlen(path))) < 0)
|
555
|
-
goto clean_up;
|
556
|
-
|
557
|
-
data.base = "";
|
558
|
-
data.baselen = 0;
|
559
|
-
data.flags = GIT_RMDIR_REMOVE_FILES;
|
560
|
-
data.error = 0;
|
561
|
-
|
562
|
-
if (!git_path_exists(path)) {
|
563
|
-
giterr_set(GITERR_OS, "Path does not exist: %s" , path);
|
564
|
-
error = GIT_ERROR;
|
565
|
-
goto clean_up;
|
566
|
-
}
|
567
|
-
|
568
|
-
if (!git_path_isdir(path)) {
|
569
|
-
giterr_set(GITERR_OS, "Path is not a directory: %s" , path);
|
570
|
-
error = GIT_ERROR;
|
571
|
-
goto clean_up;
|
820
|
+
if (error == GIT_ITEROVER) {
|
821
|
+
git_error_clear();
|
822
|
+
error = 0;
|
572
823
|
}
|
573
824
|
|
574
|
-
|
575
|
-
if (error == GIT_EUSER)
|
576
|
-
error = data.error;
|
825
|
+
git_buf_dispose(&fullpath);
|
577
826
|
|
578
|
-
clean_up:
|
579
|
-
git_buf_free(&fullpath);
|
580
827
|
return error;
|
581
828
|
}
|
582
829
|
|
583
|
-
|
584
|
-
static int git_futils_guess_system_dirs(git_buf *out)
|
585
|
-
{
|
586
|
-
#ifdef GIT_WIN32
|
587
|
-
return git_win32__find_system_dirs(out);
|
588
|
-
#else
|
589
|
-
return git_buf_sets(out, "/etc");
|
590
|
-
#endif
|
591
|
-
}
|
592
|
-
|
593
|
-
static int git_futils_guess_global_dirs(git_buf *out)
|
594
|
-
{
|
595
|
-
#ifdef GIT_WIN32
|
596
|
-
return git_win32__find_global_dirs(out);
|
597
|
-
#else
|
598
|
-
return git_buf_sets(out, getenv("HOME"));
|
599
|
-
#endif
|
600
|
-
}
|
601
|
-
|
602
|
-
static int git_futils_guess_xdg_dirs(git_buf *out)
|
603
|
-
{
|
604
|
-
#ifdef GIT_WIN32
|
605
|
-
return git_win32__find_xdg_dirs(out);
|
606
|
-
#else
|
607
|
-
const char *env = NULL;
|
608
|
-
|
609
|
-
if ((env = getenv("XDG_CONFIG_HOME")) != NULL)
|
610
|
-
return git_buf_joinpath(out, env, "git");
|
611
|
-
else if ((env = getenv("HOME")) != NULL)
|
612
|
-
return git_buf_joinpath(out, env, ".config/git");
|
613
|
-
|
614
|
-
git_buf_clear(out);
|
615
|
-
return 0;
|
616
|
-
#endif
|
617
|
-
}
|
618
|
-
|
619
|
-
typedef int (*git_futils_dirs_guess_cb)(git_buf *out);
|
620
|
-
|
621
|
-
static git_buf git_futils__dirs[GIT_FUTILS_DIR__MAX] =
|
622
|
-
{ GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT };
|
623
|
-
|
624
|
-
static git_futils_dirs_guess_cb git_futils__dir_guess[GIT_FUTILS_DIR__MAX] = {
|
625
|
-
git_futils_guess_system_dirs,
|
626
|
-
git_futils_guess_global_dirs,
|
627
|
-
git_futils_guess_xdg_dirs,
|
628
|
-
};
|
629
|
-
|
630
|
-
static int git_futils_check_selector(git_futils_dir_t which)
|
631
|
-
{
|
632
|
-
if (which < GIT_FUTILS_DIR__MAX)
|
633
|
-
return 0;
|
634
|
-
giterr_set(GITERR_INVALID, "config directory selector out of range");
|
635
|
-
return -1;
|
636
|
-
}
|
637
|
-
|
638
|
-
int git_futils_dirs_get(const git_buf **out, git_futils_dir_t which)
|
639
|
-
{
|
640
|
-
assert(out);
|
641
|
-
|
642
|
-
*out = NULL;
|
643
|
-
|
644
|
-
GITERR_CHECK_ERROR(git_futils_check_selector(which));
|
645
|
-
|
646
|
-
if (!git_buf_len(&git_futils__dirs[which]))
|
647
|
-
GITERR_CHECK_ERROR(
|
648
|
-
git_futils__dir_guess[which](&git_futils__dirs[which]));
|
649
|
-
|
650
|
-
*out = &git_futils__dirs[which];
|
651
|
-
return 0;
|
652
|
-
}
|
653
|
-
|
654
|
-
int git_futils_dirs_get_str(char *out, size_t outlen, git_futils_dir_t which)
|
655
|
-
{
|
656
|
-
const git_buf *path = NULL;
|
657
|
-
|
658
|
-
GITERR_CHECK_ERROR(git_futils_check_selector(which));
|
659
|
-
GITERR_CHECK_ERROR(git_futils_dirs_get(&path, which));
|
660
|
-
|
661
|
-
if (!out || path->size >= outlen) {
|
662
|
-
giterr_set(GITERR_NOMEMORY, "Buffer is too short for the path");
|
663
|
-
return GIT_EBUFS;
|
664
|
-
}
|
665
|
-
|
666
|
-
git_buf_copy_cstr(out, outlen, path);
|
667
|
-
return 0;
|
668
|
-
}
|
669
|
-
|
670
|
-
#define PATH_MAGIC "$PATH"
|
671
|
-
|
672
|
-
int git_futils_dirs_set(git_futils_dir_t which, const char *search_path)
|
673
|
-
{
|
674
|
-
const char *expand_path = NULL;
|
675
|
-
git_buf merge = GIT_BUF_INIT;
|
676
|
-
|
677
|
-
GITERR_CHECK_ERROR(git_futils_check_selector(which));
|
678
|
-
|
679
|
-
if (search_path != NULL)
|
680
|
-
expand_path = strstr(search_path, PATH_MAGIC);
|
681
|
-
|
682
|
-
/* init with default if not yet done and needed (ignoring error) */
|
683
|
-
if ((!search_path || expand_path) &&
|
684
|
-
!git_buf_len(&git_futils__dirs[which]))
|
685
|
-
git_futils__dir_guess[which](&git_futils__dirs[which]);
|
686
|
-
|
687
|
-
/* if $PATH is not referenced, then just set the path */
|
688
|
-
if (!expand_path)
|
689
|
-
return git_buf_sets(&git_futils__dirs[which], search_path);
|
690
|
-
|
691
|
-
/* otherwise set to join(before $PATH, old value, after $PATH) */
|
692
|
-
if (expand_path > search_path)
|
693
|
-
git_buf_set(&merge, search_path, expand_path - search_path);
|
694
|
-
|
695
|
-
if (git_buf_len(&git_futils__dirs[which]))
|
696
|
-
git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR,
|
697
|
-
merge.ptr, git_futils__dirs[which].ptr);
|
698
|
-
|
699
|
-
expand_path += strlen(PATH_MAGIC);
|
700
|
-
if (*expand_path)
|
701
|
-
git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path);
|
702
|
-
|
703
|
-
git_buf_swap(&git_futils__dirs[which], &merge);
|
704
|
-
git_buf_free(&merge);
|
705
|
-
|
706
|
-
return git_buf_oom(&git_futils__dirs[which]) ? -1 : 0;
|
707
|
-
}
|
708
|
-
|
709
|
-
void git_futils_dirs_free(void)
|
710
|
-
{
|
711
|
-
int i;
|
712
|
-
for (i = 0; i < GIT_FUTILS_DIR__MAX; ++i)
|
713
|
-
git_buf_free(&git_futils__dirs[i]);
|
714
|
-
}
|
715
|
-
|
716
|
-
static int git_futils_find_in_dirlist(
|
717
|
-
git_buf *path, const char *name, git_futils_dir_t which, const char *label)
|
718
|
-
{
|
719
|
-
size_t len;
|
720
|
-
const char *scan, *next = NULL;
|
721
|
-
const git_buf *syspath;
|
722
|
-
|
723
|
-
GITERR_CHECK_ERROR(git_futils_dirs_get(&syspath, which));
|
724
|
-
|
725
|
-
for (scan = git_buf_cstr(syspath); scan; scan = next) {
|
726
|
-
for (next = strchr(scan, GIT_PATH_LIST_SEPARATOR);
|
727
|
-
next && next > scan && next[-1] == '\\';
|
728
|
-
next = strchr(next + 1, GIT_PATH_LIST_SEPARATOR))
|
729
|
-
/* find unescaped separator or end of string */;
|
730
|
-
|
731
|
-
len = next ? (size_t)(next++ - scan) : strlen(scan);
|
732
|
-
if (!len)
|
733
|
-
continue;
|
734
|
-
|
735
|
-
GITERR_CHECK_ERROR(git_buf_set(path, scan, len));
|
736
|
-
GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
|
737
|
-
|
738
|
-
if (git_path_exists(path->ptr))
|
739
|
-
return 0;
|
740
|
-
}
|
741
|
-
|
742
|
-
git_buf_clear(path);
|
743
|
-
giterr_set(GITERR_OS, "The %s file '%s' doesn't exist", label, name);
|
744
|
-
return GIT_ENOTFOUND;
|
745
|
-
}
|
746
|
-
|
747
|
-
int git_futils_find_system_file(git_buf *path, const char *filename)
|
748
|
-
{
|
749
|
-
return git_futils_find_in_dirlist(
|
750
|
-
path, filename, GIT_FUTILS_DIR_SYSTEM, "system");
|
751
|
-
}
|
752
|
-
|
753
|
-
int git_futils_find_global_file(git_buf *path, const char *filename)
|
754
|
-
{
|
755
|
-
return git_futils_find_in_dirlist(
|
756
|
-
path, filename, GIT_FUTILS_DIR_GLOBAL, "global");
|
757
|
-
}
|
758
|
-
|
759
|
-
int git_futils_find_xdg_file(git_buf *path, const char *filename)
|
760
|
-
{
|
761
|
-
return git_futils_find_in_dirlist(
|
762
|
-
path, filename, GIT_FUTILS_DIR_XDG, "global/xdg");
|
763
|
-
}
|
764
|
-
|
765
830
|
int git_futils_fake_symlink(const char *old, const char *new)
|
766
831
|
{
|
767
832
|
int retcode = GIT_ERROR;
|
@@ -776,7 +841,7 @@ int git_futils_fake_symlink(const char *old, const char *new)
|
|
776
841
|
static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done)
|
777
842
|
{
|
778
843
|
int error = 0;
|
779
|
-
char buffer[
|
844
|
+
char buffer[FILEIO_BUFSIZE];
|
780
845
|
ssize_t len = 0;
|
781
846
|
|
782
847
|
while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0)
|
@@ -786,10 +851,13 @@ static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done)
|
|
786
851
|
error = p_write(ofd, buffer, len);
|
787
852
|
|
788
853
|
if (len < 0) {
|
789
|
-
|
854
|
+
git_error_set(GIT_ERROR_OS, "read error while copying file");
|
790
855
|
error = (int)len;
|
791
856
|
}
|
792
857
|
|
858
|
+
if (error < 0)
|
859
|
+
git_error_set(GIT_ERROR_OS, "write error while copying file");
|
860
|
+
|
793
861
|
if (close_fd_when_done) {
|
794
862
|
p_close(ifd);
|
795
863
|
p_close(ofd);
|
@@ -806,33 +874,47 @@ int git_futils_cp(const char *from, const char *to, mode_t filemode)
|
|
806
874
|
return ifd;
|
807
875
|
|
808
876
|
if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
|
809
|
-
if (errno == ENOENT || errno == ENOTDIR)
|
810
|
-
ofd = GIT_ENOTFOUND;
|
811
|
-
giterr_set(GITERR_OS, "Failed to open '%s' for writing", to);
|
812
877
|
p_close(ifd);
|
813
|
-
return
|
878
|
+
return git_path_set_error(errno, to, "open for writing");
|
814
879
|
}
|
815
880
|
|
816
881
|
return cp_by_fd(ifd, ofd, true);
|
817
882
|
}
|
818
883
|
|
884
|
+
int git_futils_touch(const char *path, time_t *when)
|
885
|
+
{
|
886
|
+
struct p_timeval times[2];
|
887
|
+
int ret;
|
888
|
+
|
889
|
+
times[0].tv_sec = times[1].tv_sec = when ? *when : time(NULL);
|
890
|
+
times[0].tv_usec = times[1].tv_usec = 0;
|
891
|
+
|
892
|
+
ret = p_utimes(path, times);
|
893
|
+
|
894
|
+
return (ret < 0) ? git_path_set_error(errno, path, "touch") : 0;
|
895
|
+
}
|
896
|
+
|
819
897
|
static int cp_link(const char *from, const char *to, size_t link_size)
|
820
898
|
{
|
821
899
|
int error = 0;
|
822
900
|
ssize_t read_len;
|
823
|
-
char *link_data
|
824
|
-
|
901
|
+
char *link_data;
|
902
|
+
size_t alloc_size;
|
903
|
+
|
904
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1);
|
905
|
+
link_data = git__malloc(alloc_size);
|
906
|
+
GIT_ERROR_CHECK_ALLOC(link_data);
|
825
907
|
|
826
908
|
read_len = p_readlink(from, link_data, link_size);
|
827
909
|
if (read_len != (ssize_t)link_size) {
|
828
|
-
|
910
|
+
git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", from);
|
829
911
|
error = -1;
|
830
912
|
}
|
831
913
|
else {
|
832
914
|
link_data[read_len] = '\0';
|
833
915
|
|
834
916
|
if (p_symlink(link_data, to) < 0) {
|
835
|
-
|
917
|
+
git_error_set(GIT_ERROR_OS, "could not symlink '%s' as '%s'",
|
836
918
|
link_data, to);
|
837
919
|
error = -1;
|
838
920
|
}
|
@@ -860,7 +942,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
|
|
860
942
|
/* create root directory the first time we need to create a directory */
|
861
943
|
if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) {
|
862
944
|
error = git_futils_mkdir(
|
863
|
-
info->to_root,
|
945
|
+
info->to_root, info->dirmode,
|
864
946
|
(info->flags & GIT_CPDIR_CHMOD_DIRS) ? GIT_MKDIR_CHMOD : 0);
|
865
947
|
|
866
948
|
info->flags |= GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT;
|
@@ -868,9 +950,9 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
|
|
868
950
|
|
869
951
|
/* create directory with root as base to prevent excess chmods */
|
870
952
|
if (!error)
|
871
|
-
error =
|
953
|
+
error = git_futils_mkdir_relative(
|
872
954
|
from->ptr + info->from_prefix, info->to_root,
|
873
|
-
info->dirmode, info->mkdir_flags);
|
955
|
+
info->dirmode, info->mkdir_flags, NULL);
|
874
956
|
|
875
957
|
return error;
|
876
958
|
}
|
@@ -886,18 +968,18 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
886
968
|
from->ptr[git_path_basename_offset(from)] == '.')
|
887
969
|
return 0;
|
888
970
|
|
889
|
-
if (git_buf_joinpath(
|
890
|
-
&info->to, info->to_root, from->ptr + info->from_prefix) < 0)
|
891
|
-
return
|
971
|
+
if ((error = git_buf_joinpath(
|
972
|
+
&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
|
973
|
+
return error;
|
892
974
|
|
893
|
-
if (
|
894
|
-
if (errno != ENOENT && errno != ENOTDIR) {
|
895
|
-
giterr_set(GITERR_OS,
|
896
|
-
"Could not access %s while copying files", info->to.ptr);
|
897
|
-
return -1;
|
898
|
-
}
|
899
|
-
} else
|
975
|
+
if (!(error = git_path_lstat(info->to.ptr, &to_st)))
|
900
976
|
exists = true;
|
977
|
+
else if (error != GIT_ENOTFOUND)
|
978
|
+
return error;
|
979
|
+
else {
|
980
|
+
git_error_clear();
|
981
|
+
error = 0;
|
982
|
+
}
|
901
983
|
|
902
984
|
if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
|
903
985
|
return error;
|
@@ -915,7 +997,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
915
997
|
|
916
998
|
/* recurse onto target directory */
|
917
999
|
if (!error && (!exists || S_ISDIR(to_st.st_mode)))
|
918
|
-
error = git_path_direach(from, _cp_r_callback, info);
|
1000
|
+
error = git_path_direach(from, 0, _cp_r_callback, info);
|
919
1001
|
|
920
1002
|
if (oldmode != 0)
|
921
1003
|
info->dirmode = oldmode;
|
@@ -928,9 +1010,9 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
928
1010
|
return 0;
|
929
1011
|
|
930
1012
|
if (p_unlink(info->to.ptr) < 0) {
|
931
|
-
|
1013
|
+
git_error_set(GIT_ERROR_OS, "cannot overwrite existing file '%s'",
|
932
1014
|
info->to.ptr);
|
933
|
-
return
|
1015
|
+
return GIT_EEXISTS;
|
934
1016
|
}
|
935
1017
|
}
|
936
1018
|
|
@@ -946,13 +1028,16 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
946
1028
|
return error;
|
947
1029
|
|
948
1030
|
/* make symlink or regular file */
|
949
|
-
if (
|
1031
|
+
if (info->flags & GIT_CPDIR_LINK_FILES) {
|
1032
|
+
if ((error = p_link(from->ptr, info->to.ptr)) < 0)
|
1033
|
+
git_error_set(GIT_ERROR_OS, "failed to link '%s'", from->ptr);
|
1034
|
+
} else if (S_ISLNK(from_st.st_mode)) {
|
950
1035
|
error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size);
|
951
|
-
else {
|
1036
|
+
} else {
|
952
1037
|
mode_t usemode = from_st.st_mode;
|
953
1038
|
|
954
1039
|
if ((info->flags & GIT_CPDIR_SIMPLE_TO_MODE) != 0)
|
955
|
-
usemode = (usemode
|
1040
|
+
usemode = GIT_PERMS_FOR_WRITE(usemode);
|
956
1041
|
|
957
1042
|
error = git_futils_cp(from->ptr, info->to.ptr, usemode);
|
958
1043
|
}
|
@@ -973,6 +1058,7 @@ int git_futils_cp_r(
|
|
973
1058
|
if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
|
974
1059
|
return -1;
|
975
1060
|
|
1061
|
+
memset(&info, 0, sizeof(info));
|
976
1062
|
info.to_root = to;
|
977
1063
|
info.flags = flags;
|
978
1064
|
info.dirmode = dirmode;
|
@@ -995,8 +1081,8 @@ int git_futils_cp_r(
|
|
995
1081
|
|
996
1082
|
error = _cp_r_callback(&info, &path);
|
997
1083
|
|
998
|
-
|
999
|
-
|
1084
|
+
git_buf_dispose(&path);
|
1085
|
+
git_buf_dispose(&info.to);
|
1000
1086
|
|
1001
1087
|
return error;
|
1002
1088
|
}
|
@@ -1010,17 +1096,21 @@ int git_futils_filestamp_check(
|
|
1010
1096
|
if (stamp == NULL)
|
1011
1097
|
return 1;
|
1012
1098
|
|
1013
|
-
if (p_stat(path, &st) < 0)
|
1014
|
-
giterr_set(GITERR_OS, "Could not stat '%s'", path);
|
1099
|
+
if (p_stat(path, &st) < 0)
|
1015
1100
|
return GIT_ENOTFOUND;
|
1016
|
-
}
|
1017
1101
|
|
1018
|
-
if (stamp->mtime ==
|
1102
|
+
if (stamp->mtime.tv_sec == st.st_mtime &&
|
1103
|
+
#if defined(GIT_USE_NSEC)
|
1104
|
+
stamp->mtime.tv_nsec == st.st_mtime_nsec &&
|
1105
|
+
#endif
|
1019
1106
|
stamp->size == (git_off_t)st.st_size &&
|
1020
1107
|
stamp->ino == (unsigned int)st.st_ino)
|
1021
1108
|
return 0;
|
1022
1109
|
|
1023
|
-
stamp->mtime =
|
1110
|
+
stamp->mtime.tv_sec = st.st_mtime;
|
1111
|
+
#if defined(GIT_USE_NSEC)
|
1112
|
+
stamp->mtime.tv_nsec = st.st_mtime_nsec;
|
1113
|
+
#endif
|
1024
1114
|
stamp->size = (git_off_t)st.st_size;
|
1025
1115
|
stamp->ino = (unsigned int)st.st_ino;
|
1026
1116
|
|
@@ -1037,3 +1127,55 @@ void git_futils_filestamp_set(
|
|
1037
1127
|
else
|
1038
1128
|
memset(target, 0, sizeof(*target));
|
1039
1129
|
}
|
1130
|
+
|
1131
|
+
|
1132
|
+
void git_futils_filestamp_set_from_stat(
|
1133
|
+
git_futils_filestamp *stamp, struct stat *st)
|
1134
|
+
{
|
1135
|
+
if (st) {
|
1136
|
+
stamp->mtime.tv_sec = st->st_mtime;
|
1137
|
+
#if defined(GIT_USE_NSEC)
|
1138
|
+
stamp->mtime.tv_nsec = st->st_mtime_nsec;
|
1139
|
+
#else
|
1140
|
+
stamp->mtime.tv_nsec = 0;
|
1141
|
+
#endif
|
1142
|
+
stamp->size = (git_off_t)st->st_size;
|
1143
|
+
stamp->ino = (unsigned int)st->st_ino;
|
1144
|
+
} else {
|
1145
|
+
memset(stamp, 0, sizeof(*stamp));
|
1146
|
+
}
|
1147
|
+
}
|
1148
|
+
|
1149
|
+
int git_futils_fsync_dir(const char *path)
|
1150
|
+
{
|
1151
|
+
#ifdef GIT_WIN32
|
1152
|
+
GIT_UNUSED(path);
|
1153
|
+
return 0;
|
1154
|
+
#else
|
1155
|
+
int fd, error = -1;
|
1156
|
+
|
1157
|
+
if ((fd = p_open(path, O_RDONLY)) < 0) {
|
1158
|
+
git_error_set(GIT_ERROR_OS, "failed to open directory '%s' for fsync", path);
|
1159
|
+
return -1;
|
1160
|
+
}
|
1161
|
+
|
1162
|
+
if ((error = p_fsync(fd)) < 0)
|
1163
|
+
git_error_set(GIT_ERROR_OS, "failed to fsync directory '%s'", path);
|
1164
|
+
|
1165
|
+
p_close(fd);
|
1166
|
+
return error;
|
1167
|
+
#endif
|
1168
|
+
}
|
1169
|
+
|
1170
|
+
int git_futils_fsync_parent(const char *path)
|
1171
|
+
{
|
1172
|
+
char *parent;
|
1173
|
+
int error;
|
1174
|
+
|
1175
|
+
if ((parent = git_path_dirname(path)) == NULL)
|
1176
|
+
return -1;
|
1177
|
+
|
1178
|
+
error = git_futils_fsync_dir(parent);
|
1179
|
+
git__free(parent);
|
1180
|
+
return error;
|
1181
|
+
}
|