rugged 1.3.2.3 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/rugged/extconf.rb +1 -1
- data/ext/rugged/rugged_config.c +7 -2
- data/ext/rugged/rugged_remote.c +17 -0
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +103 -276
- data/vendor/libgit2/COPYING +36 -19
- data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
- data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
- data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
- data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
- data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
- data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
- data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
- data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
- data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
- data/vendor/libgit2/cmake/FindPCRE.cmake +13 -13
- data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
- data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
- data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
- data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
- data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
- data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
- data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
- data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
- data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
- data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
- data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
- data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -100
- data/vendor/libgit2/cmake/SelectHashes.cmake +39 -49
- data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
- data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
- data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
- data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
- data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
- data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +31 -31
- data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +1 -1
- data/vendor/libgit2/deps/ntlmclient/ntlm.c +4 -4
- data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
- data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
- data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
- data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
- data/vendor/libgit2/deps/zlib/adler32.c +0 -7
- data/vendor/libgit2/deps/zlib/crc32.c +288 -975
- data/vendor/libgit2/deps/zlib/crc32.h +436 -9441
- data/vendor/libgit2/deps/zlib/deflate.c +31 -83
- data/vendor/libgit2/deps/zlib/deflate.h +15 -12
- data/vendor/libgit2/deps/zlib/gzguts.h +2 -3
- data/vendor/libgit2/deps/zlib/infback.c +1 -2
- data/vendor/libgit2/deps/zlib/inffast.c +14 -14
- data/vendor/libgit2/deps/zlib/inflate.c +8 -39
- data/vendor/libgit2/deps/zlib/inflate.h +2 -3
- data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
- data/vendor/libgit2/deps/zlib/trees.c +48 -27
- data/vendor/libgit2/deps/zlib/zlib.h +100 -126
- data/vendor/libgit2/deps/zlib/zutil.c +2 -2
- data/vendor/libgit2/deps/zlib/zutil.h +9 -12
- data/vendor/libgit2/include/git2/apply.h +16 -2
- data/vendor/libgit2/include/git2/attr.h +11 -2
- data/vendor/libgit2/include/git2/blame.h +4 -1
- data/vendor/libgit2/include/git2/blob.h +14 -1
- data/vendor/libgit2/include/git2/branch.h +2 -0
- data/vendor/libgit2/include/git2/buffer.h +18 -78
- data/vendor/libgit2/include/git2/cert.h +2 -2
- data/vendor/libgit2/include/git2/checkout.h +5 -2
- data/vendor/libgit2/include/git2/clone.h +3 -3
- data/vendor/libgit2/include/git2/commit.h +2 -0
- data/vendor/libgit2/include/git2/common.h +5 -12
- data/vendor/libgit2/include/git2/config.h +19 -3
- data/vendor/libgit2/include/git2/credential.h +2 -1
- data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
- data/vendor/libgit2/include/git2/deprecated.h +1 -1
- data/vendor/libgit2/include/git2/describe.h +7 -2
- data/vendor/libgit2/include/git2/diff.h +17 -9
- data/vendor/libgit2/include/git2/email.h +1 -1
- data/vendor/libgit2/include/git2/errors.h +1 -2
- data/vendor/libgit2/include/git2/filter.h +7 -2
- data/vendor/libgit2/include/git2/graph.h +1 -0
- data/vendor/libgit2/include/git2/ignore.h +1 -1
- data/vendor/libgit2/include/git2/index.h +11 -5
- data/vendor/libgit2/include/git2/indexer.h +19 -0
- data/vendor/libgit2/include/git2/merge.h +23 -3
- data/vendor/libgit2/include/git2/message.h +2 -0
- data/vendor/libgit2/include/git2/object.h +23 -0
- data/vendor/libgit2/include/git2/odb.h +37 -7
- data/vendor/libgit2/include/git2/odb_backend.h +1 -1
- data/vendor/libgit2/include/git2/pack.h +24 -8
- data/vendor/libgit2/include/git2/patch.h +8 -0
- data/vendor/libgit2/include/git2/pathspec.h +1 -1
- data/vendor/libgit2/include/git2/proxy.h +1 -1
- data/vendor/libgit2/include/git2/rebase.h +9 -1
- data/vendor/libgit2/include/git2/refdb.h +3 -0
- data/vendor/libgit2/include/git2/reflog.h +1 -1
- data/vendor/libgit2/include/git2/refs.h +2 -2
- data/vendor/libgit2/include/git2/remote.h +184 -37
- data/vendor/libgit2/include/git2/repository.h +14 -9
- data/vendor/libgit2/include/git2/reset.h +2 -2
- data/vendor/libgit2/include/git2/revparse.h +1 -1
- data/vendor/libgit2/include/git2/revwalk.h +4 -1
- data/vendor/libgit2/include/git2/signature.h +1 -1
- data/vendor/libgit2/include/git2/stash.h +3 -3
- data/vendor/libgit2/include/git2/status.h +9 -3
- data/vendor/libgit2/include/git2/submodule.h +7 -2
- data/vendor/libgit2/include/git2/sys/commit_graph.h +1 -1
- data/vendor/libgit2/include/git2/sys/odb_backend.h +2 -5
- data/vendor/libgit2/include/git2/sys/remote.h +31 -0
- data/vendor/libgit2/include/git2/sys/stream.h +1 -1
- data/vendor/libgit2/include/git2/sys/transport.h +25 -34
- data/vendor/libgit2/include/git2/tag.h +1 -0
- data/vendor/libgit2/include/git2/tree.h +4 -3
- data/vendor/libgit2/include/git2/types.h +7 -7
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/include/git2/worktree.h +12 -2
- data/vendor/libgit2/src/CMakeLists.txt +189 -315
- data/vendor/libgit2/src/annotated_commit.h +1 -1
- data/vendor/libgit2/src/apply.c +18 -18
- data/vendor/libgit2/src/apply.h +2 -2
- data/vendor/libgit2/src/attr.c +18 -18
- data/vendor/libgit2/src/attr_file.c +17 -17
- data/vendor/libgit2/src/attr_file.h +4 -4
- data/vendor/libgit2/src/attrcache.c +17 -12
- data/vendor/libgit2/src/blame_git.c +1 -1
- data/vendor/libgit2/src/blob.c +33 -26
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +150 -109
- data/vendor/libgit2/src/branch.h +15 -3
- data/vendor/libgit2/src/buf.c +126 -0
- data/vendor/libgit2/src/buf.h +50 -0
- data/vendor/libgit2/src/cc-compat.h +1 -1
- data/vendor/libgit2/src/checkout.c +74 -68
- data/vendor/libgit2/src/cherrypick.c +10 -10
- data/vendor/libgit2/src/clone.c +66 -66
- data/vendor/libgit2/src/commit.c +128 -58
- data/vendor/libgit2/src/commit.h +24 -1
- data/vendor/libgit2/src/commit_graph.c +68 -53
- data/vendor/libgit2/src/commit_graph.h +10 -3
- data/vendor/libgit2/src/commit_list.c +2 -3
- data/vendor/libgit2/src/common.h +10 -3
- data/vendor/libgit2/src/config.c +99 -77
- data/vendor/libgit2/src/config.h +15 -2
- data/vendor/libgit2/src/config_file.c +103 -91
- data/vendor/libgit2/src/config_mem.c +9 -9
- data/vendor/libgit2/src/config_parse.c +27 -23
- data/vendor/libgit2/src/crlf.c +24 -21
- data/vendor/libgit2/src/date.c +10 -17
- data/vendor/libgit2/src/date.h +33 -0
- data/vendor/libgit2/src/describe.c +27 -19
- data/vendor/libgit2/src/diff.c +25 -8
- data/vendor/libgit2/src/diff.h +2 -4
- data/vendor/libgit2/src/diff_driver.c +34 -36
- data/vendor/libgit2/src/diff_driver.h +3 -3
- data/vendor/libgit2/src/diff_file.c +29 -20
- data/vendor/libgit2/src/diff_generate.c +30 -6
- data/vendor/libgit2/src/diff_generate.h +5 -3
- data/vendor/libgit2/src/diff_print.c +102 -95
- data/vendor/libgit2/src/diff_stats.c +40 -29
- data/vendor/libgit2/src/{message.h → diff_stats.h} +7 -6
- data/vendor/libgit2/src/diff_tform.c +9 -8
- data/vendor/libgit2/src/diff_xdiff.c +3 -8
- data/vendor/libgit2/src/email.c +54 -38
- data/vendor/libgit2/src/email.h +1 -1
- data/vendor/libgit2/src/errors.c +18 -18
- data/vendor/libgit2/src/features.h.in +6 -1
- data/vendor/libgit2/src/fetch.c +69 -24
- data/vendor/libgit2/src/fetch.h +1 -1
- data/vendor/libgit2/src/fetchhead.c +19 -19
- data/vendor/libgit2/src/filebuf.c +28 -28
- data/vendor/libgit2/src/filebuf.h +1 -1
- data/vendor/libgit2/src/filter.c +96 -52
- data/vendor/libgit2/src/filter.h +26 -5
- data/vendor/libgit2/src/fs_path.c +1912 -0
- data/vendor/libgit2/src/fs_path.h +752 -0
- data/vendor/libgit2/src/futils.c +91 -85
- data/vendor/libgit2/src/futils.h +26 -14
- data/vendor/libgit2/src/hash/sha1/collisiondetect.c +2 -2
- data/vendor/libgit2/src/hash/sha1/common_crypto.c +2 -2
- data/vendor/libgit2/src/hash/sha1/generic.c +2 -2
- data/vendor/libgit2/src/hash/sha1/mbedtls.c +2 -2
- data/vendor/libgit2/src/hash/sha1/openssl.c +2 -2
- data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +1 -1
- data/vendor/libgit2/src/hash/sha1/win32.c +6 -6
- data/vendor/libgit2/src/hash/sha1.h +3 -1
- data/vendor/libgit2/src/hash.c +67 -35
- data/vendor/libgit2/src/hash.h +12 -12
- data/vendor/libgit2/src/ident.c +18 -18
- data/vendor/libgit2/src/ignore.c +35 -34
- data/vendor/libgit2/src/ignore.h +2 -2
- data/vendor/libgit2/src/index.c +79 -80
- data/vendor/libgit2/src/index.h +6 -3
- data/vendor/libgit2/src/indexer.c +75 -57
- data/vendor/libgit2/src/iterator.c +64 -56
- data/vendor/libgit2/src/iterator.h +5 -5
- data/vendor/libgit2/src/khash.h +1 -1
- data/vendor/libgit2/src/libgit2.c +22 -19
- data/vendor/libgit2/src/mailmap.c +38 -36
- data/vendor/libgit2/src/merge.c +27 -27
- data/vendor/libgit2/src/merge.h +1 -14
- data/vendor/libgit2/src/merge_driver.c +2 -2
- data/vendor/libgit2/src/merge_file.c +13 -3
- data/vendor/libgit2/src/message.c +21 -10
- data/vendor/libgit2/src/midx.c +83 -66
- data/vendor/libgit2/src/midx.h +3 -3
- data/vendor/libgit2/src/mwindow.c +1 -1
- data/vendor/libgit2/src/net.c +278 -68
- data/vendor/libgit2/src/net.h +10 -3
- data/vendor/libgit2/src/netops.c +1 -1
- data/vendor/libgit2/src/netops.h +1 -1
- data/vendor/libgit2/src/notes.c +20 -29
- data/vendor/libgit2/src/object.c +49 -9
- data/vendor/libgit2/src/object.h +1 -1
- data/vendor/libgit2/src/odb.c +35 -32
- data/vendor/libgit2/src/odb.h +1 -1
- data/vendor/libgit2/src/odb_loose.c +68 -68
- data/vendor/libgit2/src/odb_mempack.c +18 -5
- data/vendor/libgit2/src/odb_pack.c +43 -43
- data/vendor/libgit2/src/oid.c +11 -4
- data/vendor/libgit2/src/oid.h +15 -0
- data/vendor/libgit2/src/pack-objects.c +41 -26
- data/vendor/libgit2/src/pack-objects.h +11 -6
- data/vendor/libgit2/src/pack.c +10 -10
- data/vendor/libgit2/src/patch.c +3 -3
- data/vendor/libgit2/src/patch.h +1 -0
- data/vendor/libgit2/src/patch_generate.c +27 -11
- data/vendor/libgit2/src/patch_generate.h +5 -5
- data/vendor/libgit2/src/patch_parse.c +24 -24
- data/vendor/libgit2/src/path.c +76 -1951
- data/vendor/libgit2/src/path.h +34 -741
- data/vendor/libgit2/src/pathspec.c +6 -6
- data/vendor/libgit2/src/pathspec.h +2 -2
- data/vendor/libgit2/src/posix.c +3 -3
- data/vendor/libgit2/src/posix.h +1 -0
- data/vendor/libgit2/src/pqueue.h +1 -1
- data/vendor/libgit2/src/proxy.c +4 -1
- data/vendor/libgit2/src/proxy.h +1 -1
- data/vendor/libgit2/src/push.c +30 -35
- data/vendor/libgit2/src/push.h +4 -16
- data/vendor/libgit2/src/rand.c +226 -0
- data/vendor/libgit2/src/rand.h +37 -0
- data/vendor/libgit2/src/reader.c +8 -8
- data/vendor/libgit2/src/reader.h +2 -2
- data/vendor/libgit2/src/rebase.c +89 -88
- data/vendor/libgit2/src/refdb_fs.c +447 -173
- data/vendor/libgit2/src/refs.c +32 -32
- data/vendor/libgit2/src/refs.h +2 -2
- data/vendor/libgit2/src/refspec.c +32 -37
- data/vendor/libgit2/src/refspec.h +5 -2
- data/vendor/libgit2/src/regexp.c +1 -1
- data/vendor/libgit2/src/remote.c +713 -419
- data/vendor/libgit2/src/remote.h +15 -10
- data/vendor/libgit2/src/repository.c +350 -467
- data/vendor/libgit2/src/repository.h +11 -10
- data/vendor/libgit2/src/reset.c +8 -5
- data/vendor/libgit2/src/revert.c +10 -10
- data/vendor/libgit2/src/revparse.c +48 -35
- data/vendor/libgit2/src/revwalk.c +7 -7
- data/vendor/libgit2/src/signature.c +12 -6
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/sortedcache.c +1 -1
- data/vendor/libgit2/src/sortedcache.h +1 -1
- data/vendor/libgit2/src/stash.c +36 -37
- data/vendor/libgit2/src/status.c +4 -1
- data/vendor/libgit2/src/{buffer.c → str.c} +157 -151
- data/vendor/libgit2/src/str.h +357 -0
- data/vendor/libgit2/src/streams/mbedtls.c +8 -6
- data/vendor/libgit2/src/streams/openssl_dynamic.h +3 -3
- data/vendor/libgit2/src/submodule.c +171 -159
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/sysdir.c +68 -52
- data/vendor/libgit2/src/sysdir.h +15 -10
- data/vendor/libgit2/src/tag.c +29 -27
- data/vendor/libgit2/src/thread.h +3 -3
- data/vendor/libgit2/src/threadstate.c +3 -3
- data/vendor/libgit2/src/threadstate.h +1 -1
- data/vendor/libgit2/src/trace.c +1 -14
- data/vendor/libgit2/src/trace.h +5 -22
- data/vendor/libgit2/src/trailer.c +1 -1
- data/vendor/libgit2/src/transaction.c +1 -1
- data/vendor/libgit2/src/transport.c +10 -10
- data/vendor/libgit2/src/transports/auth.c +7 -9
- data/vendor/libgit2/src/transports/auth.h +2 -3
- data/vendor/libgit2/src/transports/auth_negotiate.c +12 -13
- data/vendor/libgit2/src/transports/auth_ntlm.c +10 -10
- data/vendor/libgit2/src/transports/auth_ntlm.h +0 -1
- data/vendor/libgit2/src/transports/git.c +9 -11
- data/vendor/libgit2/src/transports/http.c +37 -17
- data/vendor/libgit2/src/transports/http.h +2 -3
- data/vendor/libgit2/src/transports/httpclient.c +65 -65
- data/vendor/libgit2/src/transports/local.c +124 -116
- data/vendor/libgit2/src/transports/smart.c +51 -139
- data/vendor/libgit2/src/transports/smart.h +25 -31
- data/vendor/libgit2/src/transports/smart_pkt.c +33 -33
- data/vendor/libgit2/src/transports/smart_protocol.c +57 -39
- data/vendor/libgit2/src/transports/ssh.c +47 -112
- data/vendor/libgit2/src/transports/winhttp.c +50 -56
- data/vendor/libgit2/src/tree-cache.c +5 -5
- data/vendor/libgit2/src/tree-cache.h +2 -2
- data/vendor/libgit2/src/tree.c +59 -48
- data/vendor/libgit2/src/tree.h +1 -1
- data/vendor/libgit2/src/unix/map.c +0 -2
- data/vendor/libgit2/src/unix/posix.h +1 -4
- data/vendor/libgit2/src/unix/realpath.c +0 -2
- data/vendor/libgit2/src/util.c +14 -14
- data/vendor/libgit2/src/util.h +2 -28
- data/vendor/libgit2/src/vector.h +1 -1
- data/vendor/libgit2/src/win32/findfile.c +172 -116
- data/vendor/libgit2/src/win32/findfile.h +7 -4
- data/vendor/libgit2/src/win32/path_w32.c +140 -9
- data/vendor/libgit2/src/win32/path_w32.h +2 -0
- data/vendor/libgit2/src/win32/posix.h +0 -1
- data/vendor/libgit2/src/win32/posix_w32.c +11 -27
- data/vendor/libgit2/src/win32/w32_buffer.c +2 -3
- data/vendor/libgit2/src/win32/w32_buffer.h +2 -3
- data/vendor/libgit2/src/win32/w32_leakcheck.c +1 -1
- data/vendor/libgit2/src/worktree.c +116 -94
- data/vendor/libgit2/src/worktree.h +1 -1
- data/vendor/libgit2/src/xdiff/git-xdiff.h +53 -0
- data/vendor/libgit2/src/xdiff/xdiff.h +15 -15
- data/vendor/libgit2/src/xdiff/xdiffi.c +134 -108
- data/vendor/libgit2/src/xdiff/xemit.c +23 -7
- data/vendor/libgit2/src/xdiff/xhistogram.c +87 -78
- data/vendor/libgit2/src/xdiff/xinclude.h +1 -12
- data/vendor/libgit2/src/xdiff/xmerge.c +104 -117
- data/vendor/libgit2/src/xdiff/xpatience.c +6 -17
- data/vendor/libgit2/src/xdiff/xprepare.c +15 -20
- data/vendor/libgit2/src/xdiff/xutils.c +18 -7
- data/vendor/libgit2/src/zstream.c +5 -5
- data/vendor/libgit2/src/zstream.h +4 -4
- metadata +25 -10
- data/vendor/libgit2/src/buffer.h +0 -374
data/vendor/libgit2/src/futils.c
CHANGED
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
#include "runtime.h"
|
|
11
11
|
#include "strmap.h"
|
|
12
12
|
#include "hash.h"
|
|
13
|
+
#include "rand.h"
|
|
14
|
+
|
|
13
15
|
#include <ctype.h>
|
|
14
16
|
#if GIT_WIN32
|
|
15
17
|
#include "win32/findfile.h"
|
|
16
18
|
#endif
|
|
17
19
|
|
|
20
|
+
#define GIT_FILEMODE_DEFAULT 0100666
|
|
21
|
+
|
|
18
22
|
int git_futils_mkpath2file(const char *file_path, const mode_t mode)
|
|
19
23
|
{
|
|
20
24
|
return git_futils_mkdir(
|
|
@@ -22,32 +26,31 @@ int git_futils_mkpath2file(const char *file_path, const mode_t mode)
|
|
|
22
26
|
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
int git_futils_mktmp(
|
|
29
|
+
int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode)
|
|
26
30
|
{
|
|
31
|
+
const int open_flags = O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC;
|
|
32
|
+
unsigned int tries = 32;
|
|
27
33
|
int fd;
|
|
28
|
-
mode_t mask;
|
|
29
|
-
|
|
30
|
-
p_umask(mask = p_umask(0));
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
while (tries--) {
|
|
36
|
+
uint64_t rand = git_rand_next();
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
git_str_sets(path_out, filename);
|
|
39
|
+
git_str_puts(path_out, "_git2_");
|
|
40
|
+
git_str_encode_hexstr(path_out, (void *)&rand, sizeof(uint64_t));
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"failed to create temporary file '%s'", path_out->ptr);
|
|
41
|
-
return -1;
|
|
42
|
-
}
|
|
42
|
+
if (git_str_oom(path_out))
|
|
43
|
+
return -1;
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return -1;
|
|
45
|
+
/* Note that we open with O_CREAT | O_EXCL */
|
|
46
|
+
if ((fd = p_open(path_out->ptr, open_flags, mode)) >= 0)
|
|
47
|
+
return fd;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
git_error_set(GIT_ERROR_OS,
|
|
51
|
+
"failed to create temporary file '%s'", path_out->ptr);
|
|
52
|
+
git_str_dispose(path_out);
|
|
53
|
+
return -1;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode)
|
|
@@ -99,7 +102,7 @@ int git_futils_open_ro(const char *path)
|
|
|
99
102
|
{
|
|
100
103
|
int fd = p_open(path, O_RDONLY);
|
|
101
104
|
if (fd < 0)
|
|
102
|
-
return
|
|
105
|
+
return git_fs_path_set_error(errno, path, "open");
|
|
103
106
|
return fd;
|
|
104
107
|
}
|
|
105
108
|
|
|
@@ -107,7 +110,7 @@ int git_futils_truncate(const char *path, int mode)
|
|
|
107
110
|
{
|
|
108
111
|
int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
|
|
109
112
|
if (fd < 0)
|
|
110
|
-
return
|
|
113
|
+
return git_fs_path_set_error(errno, path, "open");
|
|
111
114
|
|
|
112
115
|
close(fd);
|
|
113
116
|
return 0;
|
|
@@ -145,12 +148,12 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
|
|
|
145
148
|
return 0;
|
|
146
149
|
}
|
|
147
150
|
|
|
148
|
-
int git_futils_readbuffer_fd(
|
|
151
|
+
int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len)
|
|
149
152
|
{
|
|
150
153
|
ssize_t read_size = 0;
|
|
151
154
|
size_t alloc_len;
|
|
152
155
|
|
|
153
|
-
|
|
156
|
+
git_str_clear(buf);
|
|
154
157
|
|
|
155
158
|
if (!git__is_ssizet(len)) {
|
|
156
159
|
git_error_set(GIT_ERROR_INVALID, "read too large");
|
|
@@ -158,7 +161,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
|
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
|
|
161
|
-
if (
|
|
164
|
+
if (git_str_grow(buf, alloc_len) < 0)
|
|
162
165
|
return -1;
|
|
163
166
|
|
|
164
167
|
/* p_read loops internally to read len bytes */
|
|
@@ -166,7 +169,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
|
|
|
166
169
|
|
|
167
170
|
if (read_size != (ssize_t)len) {
|
|
168
171
|
git_error_set(GIT_ERROR_OS, "failed to read descriptor");
|
|
169
|
-
|
|
172
|
+
git_str_dispose(buf);
|
|
170
173
|
return -1;
|
|
171
174
|
}
|
|
172
175
|
|
|
@@ -177,13 +180,16 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
|
|
|
177
180
|
}
|
|
178
181
|
|
|
179
182
|
int git_futils_readbuffer_updated(
|
|
180
|
-
|
|
183
|
+
git_str *out,
|
|
184
|
+
const char *path,
|
|
185
|
+
unsigned char checksum[GIT_HASH_SHA1_SIZE],
|
|
186
|
+
int *updated)
|
|
181
187
|
{
|
|
182
188
|
int error;
|
|
183
189
|
git_file fd;
|
|
184
190
|
struct stat st;
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
git_str buf = GIT_STR_INIT;
|
|
192
|
+
unsigned char checksum_new[GIT_HASH_SHA1_SIZE];
|
|
187
193
|
|
|
188
194
|
GIT_ASSERT_ARG(out);
|
|
189
195
|
GIT_ASSERT_ARG(path && *path);
|
|
@@ -192,7 +198,7 @@ int git_futils_readbuffer_updated(
|
|
|
192
198
|
*updated = 0;
|
|
193
199
|
|
|
194
200
|
if (p_stat(path, &st) < 0)
|
|
195
|
-
return
|
|
201
|
+
return git_fs_path_set_error(errno, path, "stat");
|
|
196
202
|
|
|
197
203
|
|
|
198
204
|
if (S_ISDIR(st.st_mode)) {
|
|
@@ -216,23 +222,23 @@ int git_futils_readbuffer_updated(
|
|
|
216
222
|
p_close(fd);
|
|
217
223
|
|
|
218
224
|
if (checksum) {
|
|
219
|
-
if ((error = git_hash_buf(
|
|
220
|
-
|
|
225
|
+
if ((error = git_hash_buf(checksum_new, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
|
|
226
|
+
git_str_dispose(&buf);
|
|
221
227
|
return error;
|
|
222
228
|
}
|
|
223
229
|
|
|
224
230
|
/*
|
|
225
231
|
* If we were given a checksum, we only want to use it if it's different
|
|
226
232
|
*/
|
|
227
|
-
if (!
|
|
228
|
-
|
|
233
|
+
if (!memcmp(checksum, checksum_new, GIT_HASH_SHA1_SIZE)) {
|
|
234
|
+
git_str_dispose(&buf);
|
|
229
235
|
if (updated)
|
|
230
236
|
*updated = 0;
|
|
231
237
|
|
|
232
238
|
return 0;
|
|
233
239
|
}
|
|
234
240
|
|
|
235
|
-
|
|
241
|
+
memcpy(checksum, checksum_new, GIT_HASH_SHA1_SIZE);
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
/*
|
|
@@ -241,19 +247,19 @@ int git_futils_readbuffer_updated(
|
|
|
241
247
|
if (updated != NULL)
|
|
242
248
|
*updated = 1;
|
|
243
249
|
|
|
244
|
-
|
|
245
|
-
|
|
250
|
+
git_str_swap(out, &buf);
|
|
251
|
+
git_str_dispose(&buf);
|
|
246
252
|
|
|
247
253
|
return 0;
|
|
248
254
|
}
|
|
249
255
|
|
|
250
|
-
int git_futils_readbuffer(
|
|
256
|
+
int git_futils_readbuffer(git_str *buf, const char *path)
|
|
251
257
|
{
|
|
252
258
|
return git_futils_readbuffer_updated(buf, path, NULL, NULL);
|
|
253
259
|
}
|
|
254
260
|
|
|
255
261
|
int git_futils_writebuffer(
|
|
256
|
-
const
|
|
262
|
+
const git_str *buf, const char *path, int flags, mode_t mode)
|
|
257
263
|
{
|
|
258
264
|
int fd, do_fsync = 0, error = 0;
|
|
259
265
|
|
|
@@ -266,14 +272,14 @@ int git_futils_writebuffer(
|
|
|
266
272
|
flags &= ~O_FSYNC;
|
|
267
273
|
|
|
268
274
|
if (!mode)
|
|
269
|
-
mode =
|
|
275
|
+
mode = GIT_FILEMODE_DEFAULT;
|
|
270
276
|
|
|
271
277
|
if ((fd = p_open(path, flags, mode)) < 0) {
|
|
272
278
|
git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path);
|
|
273
279
|
return fd;
|
|
274
280
|
}
|
|
275
281
|
|
|
276
|
-
if ((error = p_write(fd,
|
|
282
|
+
if ((error = p_write(fd, git_str_cstr(buf), git_str_len(buf))) < 0) {
|
|
277
283
|
git_error_set(GIT_ERROR_OS, "could not write to '%s'", path);
|
|
278
284
|
(void)p_close(fd);
|
|
279
285
|
return error;
|
|
@@ -415,7 +421,7 @@ GIT_INLINE(int) mkdir_validate_mode(
|
|
|
415
421
|
}
|
|
416
422
|
|
|
417
423
|
GIT_INLINE(int) mkdir_canonicalize(
|
|
418
|
-
|
|
424
|
+
git_str *path,
|
|
419
425
|
uint32_t flags)
|
|
420
426
|
{
|
|
421
427
|
ssize_t root_len;
|
|
@@ -426,7 +432,7 @@ GIT_INLINE(int) mkdir_canonicalize(
|
|
|
426
432
|
}
|
|
427
433
|
|
|
428
434
|
/* Trim trailing slashes (except the root) */
|
|
429
|
-
if ((root_len =
|
|
435
|
+
if ((root_len = git_fs_path_root(path->ptr)) < 0)
|
|
430
436
|
root_len = 0;
|
|
431
437
|
else
|
|
432
438
|
root_len++;
|
|
@@ -436,18 +442,18 @@ GIT_INLINE(int) mkdir_canonicalize(
|
|
|
436
442
|
|
|
437
443
|
/* if we are not supposed to made the last element, truncate it */
|
|
438
444
|
if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
|
|
439
|
-
|
|
445
|
+
git_fs_path_dirname_r(path, path->ptr);
|
|
440
446
|
flags |= GIT_MKDIR_SKIP_LAST;
|
|
441
447
|
}
|
|
442
448
|
if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
|
|
443
|
-
|
|
449
|
+
git_fs_path_dirname_r(path, path->ptr);
|
|
444
450
|
}
|
|
445
451
|
|
|
446
452
|
/* We were either given the root path (or trimmed it to
|
|
447
453
|
* the root), we don't have anything to do.
|
|
448
454
|
*/
|
|
449
455
|
if (path->size <= (size_t)root_len)
|
|
450
|
-
|
|
456
|
+
git_str_clear(path);
|
|
451
457
|
|
|
452
458
|
return 0;
|
|
453
459
|
}
|
|
@@ -457,20 +463,20 @@ int git_futils_mkdir(
|
|
|
457
463
|
mode_t mode,
|
|
458
464
|
uint32_t flags)
|
|
459
465
|
{
|
|
460
|
-
|
|
466
|
+
git_str make_path = GIT_STR_INIT, parent_path = GIT_STR_INIT;
|
|
461
467
|
const char *relative;
|
|
462
468
|
struct git_futils_mkdir_options opts = { 0 };
|
|
463
469
|
struct stat st;
|
|
464
470
|
size_t depth = 0;
|
|
465
471
|
int len = 0, root_len, error;
|
|
466
472
|
|
|
467
|
-
if ((error =
|
|
473
|
+
if ((error = git_str_puts(&make_path, path)) < 0 ||
|
|
468
474
|
(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
|
|
469
|
-
(error =
|
|
475
|
+
(error = git_str_puts(&parent_path, make_path.ptr)) < 0 ||
|
|
470
476
|
make_path.size == 0)
|
|
471
477
|
goto done;
|
|
472
478
|
|
|
473
|
-
root_len =
|
|
479
|
+
root_len = git_fs_path_root(make_path.ptr);
|
|
474
480
|
|
|
475
481
|
/* find the first parent directory that exists. this will be used
|
|
476
482
|
* as the base to dirname_relative.
|
|
@@ -489,7 +495,7 @@ int git_futils_mkdir(
|
|
|
489
495
|
depth++;
|
|
490
496
|
|
|
491
497
|
/* examine the parent of the current path */
|
|
492
|
-
if ((len =
|
|
498
|
+
if ((len = git_fs_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
|
|
493
499
|
error = len;
|
|
494
500
|
goto done;
|
|
495
501
|
}
|
|
@@ -538,8 +544,8 @@ int git_futils_mkdir(
|
|
|
538
544
|
parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
|
|
539
545
|
|
|
540
546
|
done:
|
|
541
|
-
|
|
542
|
-
|
|
547
|
+
git_str_dispose(&make_path);
|
|
548
|
+
git_str_dispose(&parent_path);
|
|
543
549
|
return error;
|
|
544
550
|
}
|
|
545
551
|
|
|
@@ -555,7 +561,7 @@ int git_futils_mkdir_relative(
|
|
|
555
561
|
uint32_t flags,
|
|
556
562
|
struct git_futils_mkdir_options *opts)
|
|
557
563
|
{
|
|
558
|
-
|
|
564
|
+
git_str make_path = GIT_STR_INIT;
|
|
559
565
|
ssize_t root = 0, min_root_len;
|
|
560
566
|
char lastch = '/', *tail;
|
|
561
567
|
struct stat st;
|
|
@@ -566,7 +572,7 @@ int git_futils_mkdir_relative(
|
|
|
566
572
|
opts = &empty_opts;
|
|
567
573
|
|
|
568
574
|
/* build path and find "root" where we should start calling mkdir */
|
|
569
|
-
if (
|
|
575
|
+
if (git_fs_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
|
|
570
576
|
return -1;
|
|
571
577
|
|
|
572
578
|
if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
|
|
@@ -575,10 +581,10 @@ int git_futils_mkdir_relative(
|
|
|
575
581
|
|
|
576
582
|
/* if we are not supposed to make the whole path, reset root */
|
|
577
583
|
if ((flags & GIT_MKDIR_PATH) == 0)
|
|
578
|
-
root =
|
|
584
|
+
root = git_str_rfind(&make_path, '/');
|
|
579
585
|
|
|
580
586
|
/* advance root past drive name or network mount prefix */
|
|
581
|
-
min_root_len =
|
|
587
|
+
min_root_len = git_fs_path_root(make_path.ptr);
|
|
582
588
|
if (root < min_root_len)
|
|
583
589
|
root = min_root_len;
|
|
584
590
|
while (root >= 0 && make_path.ptr[root] == '/')
|
|
@@ -670,7 +676,7 @@ retry_lstat:
|
|
|
670
676
|
}
|
|
671
677
|
|
|
672
678
|
done:
|
|
673
|
-
|
|
679
|
+
git_str_dispose(&make_path);
|
|
674
680
|
return error;
|
|
675
681
|
}
|
|
676
682
|
|
|
@@ -694,13 +700,13 @@ static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
|
|
|
694
700
|
return -1;
|
|
695
701
|
}
|
|
696
702
|
|
|
697
|
-
static int futils__rm_first_parent(
|
|
703
|
+
static int futils__rm_first_parent(git_str *path, const char *ceiling)
|
|
698
704
|
{
|
|
699
705
|
int error = GIT_ENOTFOUND;
|
|
700
706
|
struct stat st;
|
|
701
707
|
|
|
702
708
|
while (error == GIT_ENOTFOUND) {
|
|
703
|
-
|
|
709
|
+
git_str_rtruncate_at_char(path, '/');
|
|
704
710
|
|
|
705
711
|
if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
|
|
706
712
|
error = 0;
|
|
@@ -719,7 +725,7 @@ static int futils__rm_first_parent(git_buf *path, const char *ceiling)
|
|
|
719
725
|
return error;
|
|
720
726
|
}
|
|
721
727
|
|
|
722
|
-
static int futils__rmdir_recurs_foreach(void *opaque,
|
|
728
|
+
static int futils__rmdir_recurs_foreach(void *opaque, git_str *path)
|
|
723
729
|
{
|
|
724
730
|
int error = 0;
|
|
725
731
|
futils__rmdir_data *data = opaque;
|
|
@@ -741,13 +747,13 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
|
|
|
741
747
|
path->ptr, "parent is not directory");
|
|
742
748
|
}
|
|
743
749
|
else
|
|
744
|
-
error =
|
|
750
|
+
error = git_fs_path_set_error(errno, path->ptr, "rmdir");
|
|
745
751
|
}
|
|
746
752
|
|
|
747
753
|
else if (S_ISDIR(st.st_mode)) {
|
|
748
754
|
data->depth++;
|
|
749
755
|
|
|
750
|
-
error =
|
|
756
|
+
error = git_fs_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
|
|
751
757
|
|
|
752
758
|
data->depth--;
|
|
753
759
|
|
|
@@ -762,13 +768,13 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
|
|
|
762
768
|
(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
|
|
763
769
|
error = 0;
|
|
764
770
|
else
|
|
765
|
-
error =
|
|
771
|
+
error = git_fs_path_set_error(errno, path->ptr, "rmdir");
|
|
766
772
|
}
|
|
767
773
|
}
|
|
768
774
|
|
|
769
775
|
else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
|
|
770
776
|
if (p_unlink(path->ptr) < 0)
|
|
771
|
-
error =
|
|
777
|
+
error = git_fs_path_set_error(errno, path->ptr, "remove");
|
|
772
778
|
}
|
|
773
779
|
|
|
774
780
|
else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
|
|
@@ -792,11 +798,11 @@ static int futils__rmdir_empty_parent(void *opaque, const char *path)
|
|
|
792
798
|
/* do nothing */
|
|
793
799
|
} else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
|
|
794
800
|
en == EBUSY) {
|
|
795
|
-
error =
|
|
801
|
+
error = git_fs_path_set_error(errno, path, "rmdir");
|
|
796
802
|
} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
|
|
797
803
|
error = GIT_ITEROVER;
|
|
798
804
|
} else {
|
|
799
|
-
error =
|
|
805
|
+
error = git_fs_path_set_error(errno, path, "rmdir");
|
|
800
806
|
}
|
|
801
807
|
}
|
|
802
808
|
|
|
@@ -807,11 +813,11 @@ int git_futils_rmdir_r(
|
|
|
807
813
|
const char *path, const char *base, uint32_t flags)
|
|
808
814
|
{
|
|
809
815
|
int error;
|
|
810
|
-
|
|
816
|
+
git_str fullpath = GIT_STR_INIT;
|
|
811
817
|
futils__rmdir_data data;
|
|
812
818
|
|
|
813
819
|
/* build path and find "root" where we should start calling mkdir */
|
|
814
|
-
if (
|
|
820
|
+
if (git_fs_path_join_unrooted(&fullpath, path, base, NULL) < 0)
|
|
815
821
|
return -1;
|
|
816
822
|
|
|
817
823
|
memset(&data, 0, sizeof(data));
|
|
@@ -823,7 +829,7 @@ int git_futils_rmdir_r(
|
|
|
823
829
|
|
|
824
830
|
/* remove now-empty parents if requested */
|
|
825
831
|
if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
|
|
826
|
-
error =
|
|
832
|
+
error = git_fs_path_walk_up(
|
|
827
833
|
&fullpath, base, futils__rmdir_empty_parent, &data);
|
|
828
834
|
|
|
829
835
|
if (error == GIT_ITEROVER) {
|
|
@@ -831,7 +837,7 @@ int git_futils_rmdir_r(
|
|
|
831
837
|
error = 0;
|
|
832
838
|
}
|
|
833
839
|
|
|
834
|
-
|
|
840
|
+
git_str_dispose(&fullpath);
|
|
835
841
|
|
|
836
842
|
return error;
|
|
837
843
|
}
|
|
@@ -884,7 +890,7 @@ int git_futils_cp(const char *from, const char *to, mode_t filemode)
|
|
|
884
890
|
|
|
885
891
|
if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
|
|
886
892
|
p_close(ifd);
|
|
887
|
-
return
|
|
893
|
+
return git_fs_path_set_error(errno, to, "open for writing");
|
|
888
894
|
}
|
|
889
895
|
|
|
890
896
|
return cp_by_fd(ifd, ofd, true);
|
|
@@ -900,7 +906,7 @@ int git_futils_touch(const char *path, time_t *when)
|
|
|
900
906
|
|
|
901
907
|
ret = p_utimes(path, times);
|
|
902
908
|
|
|
903
|
-
return (ret < 0) ?
|
|
909
|
+
return (ret < 0) ? git_fs_path_set_error(errno, path, "touch") : 0;
|
|
904
910
|
}
|
|
905
911
|
|
|
906
912
|
static int cp_link(const char *from, const char *to, size_t link_size)
|
|
@@ -935,7 +941,7 @@ static int cp_link(const char *from, const char *to, size_t link_size)
|
|
|
935
941
|
|
|
936
942
|
typedef struct {
|
|
937
943
|
const char *to_root;
|
|
938
|
-
|
|
944
|
+
git_str to;
|
|
939
945
|
ssize_t from_prefix;
|
|
940
946
|
uint32_t flags;
|
|
941
947
|
uint32_t mkdir_flags;
|
|
@@ -944,7 +950,7 @@ typedef struct {
|
|
|
944
950
|
|
|
945
951
|
#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10)
|
|
946
952
|
|
|
947
|
-
static int _cp_r_mkdir(cp_r_info *info,
|
|
953
|
+
static int _cp_r_mkdir(cp_r_info *info, git_str *from)
|
|
948
954
|
{
|
|
949
955
|
int error = 0;
|
|
950
956
|
|
|
@@ -966,7 +972,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
|
|
|
966
972
|
return error;
|
|
967
973
|
}
|
|
968
974
|
|
|
969
|
-
static int _cp_r_callback(void *ref,
|
|
975
|
+
static int _cp_r_callback(void *ref, git_str *from)
|
|
970
976
|
{
|
|
971
977
|
int error = 0;
|
|
972
978
|
cp_r_info *info = ref;
|
|
@@ -974,14 +980,14 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
|
974
980
|
bool exists = false;
|
|
975
981
|
|
|
976
982
|
if ((info->flags & GIT_CPDIR_COPY_DOTFILES) == 0 &&
|
|
977
|
-
from->ptr[
|
|
983
|
+
from->ptr[git_fs_path_basename_offset(from)] == '.')
|
|
978
984
|
return 0;
|
|
979
985
|
|
|
980
|
-
if ((error =
|
|
986
|
+
if ((error = git_str_joinpath(
|
|
981
987
|
&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
|
|
982
988
|
return error;
|
|
983
989
|
|
|
984
|
-
if (!(error =
|
|
990
|
+
if (!(error = git_fs_path_lstat(info->to.ptr, &to_st)))
|
|
985
991
|
exists = true;
|
|
986
992
|
else if (error != GIT_ENOTFOUND)
|
|
987
993
|
return error;
|
|
@@ -990,7 +996,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
|
990
996
|
error = 0;
|
|
991
997
|
}
|
|
992
998
|
|
|
993
|
-
if ((error =
|
|
999
|
+
if ((error = git_fs_path_lstat(from->ptr, &from_st)) < 0)
|
|
994
1000
|
return error;
|
|
995
1001
|
|
|
996
1002
|
if (S_ISDIR(from_st.st_mode)) {
|
|
@@ -1006,7 +1012,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
|
1006
1012
|
|
|
1007
1013
|
/* recurse onto target directory */
|
|
1008
1014
|
if (!error && (!exists || S_ISDIR(to_st.st_mode)))
|
|
1009
|
-
error =
|
|
1015
|
+
error = git_fs_path_direach(from, 0, _cp_r_callback, info);
|
|
1010
1016
|
|
|
1011
1017
|
if (oldmode != 0)
|
|
1012
1018
|
info->dirmode = oldmode;
|
|
@@ -1061,10 +1067,10 @@ int git_futils_cp_r(
|
|
|
1061
1067
|
mode_t dirmode)
|
|
1062
1068
|
{
|
|
1063
1069
|
int error;
|
|
1064
|
-
|
|
1070
|
+
git_str path = GIT_STR_INIT;
|
|
1065
1071
|
cp_r_info info;
|
|
1066
1072
|
|
|
1067
|
-
if (
|
|
1073
|
+
if (git_str_joinpath(&path, from, "") < 0) /* ensure trailing slash */
|
|
1068
1074
|
return -1;
|
|
1069
1075
|
|
|
1070
1076
|
memset(&info, 0, sizeof(info));
|
|
@@ -1072,7 +1078,7 @@ int git_futils_cp_r(
|
|
|
1072
1078
|
info.flags = flags;
|
|
1073
1079
|
info.dirmode = dirmode;
|
|
1074
1080
|
info.from_prefix = path.size;
|
|
1075
|
-
|
|
1081
|
+
git_str_init(&info.to, 0);
|
|
1076
1082
|
|
|
1077
1083
|
/* precalculate mkdir flags */
|
|
1078
1084
|
if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) {
|
|
@@ -1090,8 +1096,8 @@ int git_futils_cp_r(
|
|
|
1090
1096
|
|
|
1091
1097
|
error = _cp_r_callback(&info, &path);
|
|
1092
1098
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1099
|
+
git_str_dispose(&path);
|
|
1100
|
+
git_str_dispose(&info.to);
|
|
1095
1101
|
|
|
1096
1102
|
return error;
|
|
1097
1103
|
}
|
|
@@ -1179,7 +1185,7 @@ int git_futils_fsync_parent(const char *path)
|
|
|
1179
1185
|
char *parent;
|
|
1180
1186
|
int error;
|
|
1181
1187
|
|
|
1182
|
-
if ((parent =
|
|
1188
|
+
if ((parent = git_fs_path_dirname(path)) == NULL)
|
|
1183
1189
|
return -1;
|
|
1184
1190
|
|
|
1185
1191
|
error = git_futils_fsync_dir(parent);
|
data/vendor/libgit2/src/futils.h
CHANGED
|
@@ -11,20 +11,23 @@
|
|
|
11
11
|
|
|
12
12
|
#include "map.h"
|
|
13
13
|
#include "posix.h"
|
|
14
|
-
#include "
|
|
14
|
+
#include "fs_path.h"
|
|
15
15
|
#include "pool.h"
|
|
16
16
|
#include "strmap.h"
|
|
17
|
-
#include "
|
|
17
|
+
#include "hash.h"
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Filebuffer methods
|
|
21
21
|
*
|
|
22
22
|
* Read whole files into an in-memory buffer for processing
|
|
23
23
|
*/
|
|
24
|
-
extern int git_futils_readbuffer(
|
|
24
|
+
extern int git_futils_readbuffer(git_str *obj, const char *path);
|
|
25
25
|
extern int git_futils_readbuffer_updated(
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
git_str *obj,
|
|
27
|
+
const char *path,
|
|
28
|
+
unsigned char checksum[GIT_HASH_SHA1_SIZE],
|
|
29
|
+
int *updated);
|
|
30
|
+
extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len);
|
|
28
31
|
|
|
29
32
|
/* Additional constants for `git_futils_writebuffer`'s `open_flags`. We
|
|
30
33
|
* support these internally and they will be removed before the `open` call.
|
|
@@ -34,7 +37,7 @@ extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
|
|
|
34
37
|
#endif
|
|
35
38
|
|
|
36
39
|
extern int git_futils_writebuffer(
|
|
37
|
-
const
|
|
40
|
+
const git_str *buf, const char *path, int open_flags, mode_t mode);
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
43
|
* File utils
|
|
@@ -93,7 +96,7 @@ typedef enum {
|
|
|
93
96
|
GIT_MKDIR_SKIP_LAST2 = 32,
|
|
94
97
|
GIT_MKDIR_VERIFY_DIR = 64,
|
|
95
98
|
GIT_MKDIR_REMOVE_FILES = 128,
|
|
96
|
-
GIT_MKDIR_REMOVE_SYMLINKS = 256
|
|
99
|
+
GIT_MKDIR_REMOVE_SYMLINKS = 256
|
|
97
100
|
} git_futils_mkdir_flags;
|
|
98
101
|
|
|
99
102
|
struct git_futils_mkdir_perfdata
|
|
@@ -156,7 +159,7 @@ typedef enum {
|
|
|
156
159
|
GIT_RMDIR_SKIP_NONEMPTY = (1 << 1),
|
|
157
160
|
GIT_RMDIR_EMPTY_PARENTS = (1 << 2),
|
|
158
161
|
GIT_RMDIR_REMOVE_BLOCKERS = (1 << 3),
|
|
159
|
-
GIT_RMDIR_SKIP_ROOT = (1 << 4)
|
|
162
|
+
GIT_RMDIR_SKIP_ROOT = (1 << 4)
|
|
160
163
|
} git_futils_rmdir_flags;
|
|
161
164
|
|
|
162
165
|
/**
|
|
@@ -170,11 +173,20 @@ typedef enum {
|
|
|
170
173
|
extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags);
|
|
171
174
|
|
|
172
175
|
/**
|
|
173
|
-
* Create and open a temporary file with a `_git2_` suffix
|
|
174
|
-
*
|
|
176
|
+
* Create and open a temporary file with a `_git2_` suffix in a
|
|
177
|
+
* protected directory; the file created will created will honor
|
|
178
|
+
* the current `umask`. Writes the filename into path_out.
|
|
179
|
+
*
|
|
180
|
+
* This function uses a high-quality PRNG seeded by the system's
|
|
181
|
+
* entropy pool _where available_ and falls back to a simple seed
|
|
182
|
+
* (time plus system information) when not. This is suitable for
|
|
183
|
+
* writing within a protected directory, but the system's safe
|
|
184
|
+
* temporary file creation functions should be preferred where
|
|
185
|
+
* available when writing into world-writable (temp) directories.
|
|
186
|
+
*
|
|
175
187
|
* @return On success, an open file descriptor, else an error code < 0.
|
|
176
188
|
*/
|
|
177
|
-
extern int git_futils_mktmp(
|
|
189
|
+
extern int git_futils_mktmp(git_str *path_out, const char *filename, mode_t mode);
|
|
178
190
|
|
|
179
191
|
/**
|
|
180
192
|
* Move a file on the filesystem, create the
|
|
@@ -221,17 +233,17 @@ typedef enum {
|
|
|
221
233
|
GIT_CPDIR_OVERWRITE = (1u << 3),
|
|
222
234
|
GIT_CPDIR_CHMOD_DIRS = (1u << 4),
|
|
223
235
|
GIT_CPDIR_SIMPLE_TO_MODE = (1u << 5),
|
|
224
|
-
GIT_CPDIR_LINK_FILES = (1u << 6)
|
|
236
|
+
GIT_CPDIR_LINK_FILES = (1u << 6)
|
|
225
237
|
} git_futils_cpdir_flags;
|
|
226
238
|
|
|
227
239
|
/**
|
|
228
240
|
* Copy a directory tree.
|
|
229
241
|
*
|
|
230
242
|
* This copies directories and files from one root to another. You can
|
|
231
|
-
* pass a
|
|
243
|
+
* pass a combination of GIT_CPDIR flags as defined above.
|
|
232
244
|
*
|
|
233
245
|
* If you pass the CHMOD flag, then the dirmode will be applied to all
|
|
234
|
-
* directories that are created during the copy,
|
|
246
|
+
* directories that are created during the copy, overriding the natural
|
|
235
247
|
* permissions. If you do not pass the CHMOD flag, then the dirmode
|
|
236
248
|
* will actually be copied from the source files and the `dirmode` arg
|
|
237
249
|
* will be ignored.
|
|
@@ -36,10 +36,10 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
|
|
|
36
36
|
return 0;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
int git_hash_sha1_final(
|
|
39
|
+
int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
|
|
40
40
|
{
|
|
41
41
|
GIT_ASSERT_ARG(ctx);
|
|
42
|
-
if (SHA1DCFinal(out
|
|
42
|
+
if (SHA1DCFinal(out, &ctx->c)) {
|
|
43
43
|
git_error_set(GIT_ERROR_SHA1, "SHA1 collision attack detected");
|
|
44
44
|
return -1;
|
|
45
45
|
}
|
|
@@ -49,9 +49,9 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
|
|
|
49
49
|
return 0;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
int git_hash_sha1_final(
|
|
52
|
+
int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
|
|
53
53
|
{
|
|
54
54
|
GIT_ASSERT_ARG(ctx);
|
|
55
|
-
CC_SHA1_Final(out
|
|
55
|
+
CC_SHA1_Final(out, &ctx->c);
|
|
56
56
|
return 0;
|
|
57
57
|
}
|