rugged 0.21.2 → 0.21.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_git_path_w32_h__
8
+ #define INCLUDE_git_path_w32_h__
9
+
10
+ /*
11
+ * Provides a large enough buffer to support Windows paths: MAX_PATH is
12
+ * 260, corresponding to a maximum path length of 259 characters plus a
13
+ * NULL terminator. Prefixing with "\\?\" adds 4 characters, but if the
14
+ * original was a UNC path, then we turn "\\server\share" into
15
+ * "\\?\UNC\server\share". So we replace the first two characters with
16
+ * 8 characters, a net gain of 6, so the maximum length is MAX_PATH+6.
17
+ */
18
+ #define GIT_WIN_PATH_UTF16 MAX_PATH+6
19
+
20
+ /* Maximum size of a UTF-8 Win32 path. We remove the "\\?\" or "\\?\UNC\"
21
+ * prefixes for presentation, bringing us back to 259 (non-NULL)
22
+ * characters. UTF-8 does have 4-byte sequences, but they are encoded in
23
+ * UTF-16 using surrogate pairs, which takes up the space of two characters.
24
+ * Two characters in the range U+0800 -> U+FFFF take up more space in UTF-8
25
+ * (6 bytes) than one surrogate pair (4 bytes).
26
+ */
27
+ #define GIT_WIN_PATH_UTF8 (259 * 3 + 1)
28
+
29
+ /*
30
+ * The length of a Windows "shortname", for 8.3 compatibility.
31
+ */
32
+ #define GIT_WIN_PATH_SHORTNAME 13
33
+
34
+ /* Win32 path types */
35
+ typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
36
+ typedef char git_win32_utf8_path[GIT_WIN_PATH_UTF8];
37
+
38
+ /**
39
+ * Create a Win32 path (in UCS-2 format) from a UTF-8 string.
40
+ *
41
+ * @param dest The buffer to receive the wide string.
42
+ * @param src The UTF-8 string to convert.
43
+ * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
44
+ */
45
+ extern int git_win32_path_from_utf8(git_win32_path dest, const char *src);
46
+
47
+ /**
48
+ * Canonicalize a Win32 UCS-2 path so that it is suitable for delivery to the
49
+ * Win32 APIs: remove multiple directory separators, squashing to a single one,
50
+ * strip trailing directory separators, ensure directory separators are all
51
+ * canonical (always backslashes, never forward slashes) and process any
52
+ * directory entries of '.' or '..'.
53
+ *
54
+ * This processes the buffer in place.
55
+ *
56
+ * @param path The buffer to process
57
+ * @return The new length of the buffer, in wchar_t's (not counting the NULL terminator)
58
+ */
59
+ extern int git_win32_path_canonicalize(git_win32_path path);
60
+
61
+ /**
62
+ * Create an internal format (posix-style) UTF-8 path from a Win32 UCS-2 path.
63
+ *
64
+ * @param dest The buffer to receive the UTF-8 string.
65
+ * @param src The wide string to convert.
66
+ * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure
67
+ */
68
+ extern int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src);
69
+
70
+ /**
71
+ * Get the short name for the terminal path component in the given path.
72
+ * For example, given "C:\Foo\Bar\Asdf.txt", this will return the short name
73
+ * for the file "Asdf.txt".
74
+ *
75
+ * @param path The given path in UTF-8
76
+ * @return The name of the shortname for the given path
77
+ */
78
+ extern char *git_win32_path_8dot3_name(const char *path);
79
+
80
+ #endif
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "common.h"
11
11
  #include "../posix.h"
12
+ #include "path_w32.h"
12
13
  #include "utf-conv.h"
13
14
  #include "dir.h"
14
15
 
@@ -7,6 +7,7 @@
7
7
  #include "../posix.h"
8
8
  #include "../fileops.h"
9
9
  #include "path.h"
10
+ #include "path_w32.h"
10
11
  #include "utf-conv.h"
11
12
  #include "repository.h"
12
13
  #include "reparse.h"
@@ -31,29 +32,13 @@
31
32
  /* GetFinalPathNameByHandleW signature */
32
33
  typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
33
34
 
34
- /* Helper function which converts UTF-8 paths to UTF-16.
35
- * On failure, errno is set. */
36
- static int utf8_to_16_with_errno(git_win32_path dest, const char *src)
37
- {
38
- int len = git_win32_path_from_utf8(dest, src);
39
-
40
- if (len < 0) {
41
- if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
42
- errno = ENAMETOOLONG;
43
- else
44
- errno = EINVAL; /* Bad code point, presumably */
45
- }
46
-
47
- return len;
48
- }
49
-
50
35
  int p_mkdir(const char *path, mode_t mode)
51
36
  {
52
37
  git_win32_path buf;
53
38
 
54
39
  GIT_UNUSED(mode);
55
40
 
56
- if (utf8_to_16_with_errno(buf, path) < 0)
41
+ if (git_win32_path_from_utf8(buf, path) < 0)
57
42
  return -1;
58
43
 
59
44
  return _wmkdir(buf);
@@ -64,7 +49,7 @@ int p_unlink(const char *path)
64
49
  git_win32_path buf;
65
50
  int error;
66
51
 
67
- if (utf8_to_16_with_errno(buf, path) < 0)
52
+ if (git_win32_path_from_utf8(buf, path) < 0)
68
53
  return -1;
69
54
 
70
55
  error = _wunlink(buf);
@@ -271,7 +256,7 @@ static int do_lstat(const char *path, struct stat *buf, bool posixly_correct)
271
256
  git_win32_path path_w;
272
257
  int len;
273
258
 
274
- if ((len = utf8_to_16_with_errno(path_w, path)) < 0)
259
+ if ((len = git_win32_path_from_utf8(path_w, path)) < 0)
275
260
  return -1;
276
261
 
277
262
  git_win32__path_trim_end(path_w, len);
@@ -302,7 +287,7 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
302
287
  * could occur in the middle of the encoding of a code point,
303
288
  * we need to buffer the result on the stack. */
304
289
 
305
- if (utf8_to_16_with_errno(path_w, path) < 0 ||
290
+ if (git_win32_path_from_utf8(path_w, path) < 0 ||
306
291
  readlink_w(target_w, path_w) < 0 ||
307
292
  (len = git_win32_path_to_utf8(target, target_w)) < 0)
308
293
  return -1;
@@ -326,7 +311,7 @@ int p_open(const char *path, int flags, ...)
326
311
  git_win32_path buf;
327
312
  mode_t mode = 0;
328
313
 
329
- if (utf8_to_16_with_errno(buf, path) < 0)
314
+ if (git_win32_path_from_utf8(buf, path) < 0)
330
315
  return -1;
331
316
 
332
317
  if (flags & O_CREAT) {
@@ -344,7 +329,7 @@ int p_creat(const char *path, mode_t mode)
344
329
  {
345
330
  git_win32_path buf;
346
331
 
347
- if (utf8_to_16_with_errno(buf, path) < 0)
332
+ if (git_win32_path_from_utf8(buf, path) < 0)
348
333
  return -1;
349
334
 
350
335
  return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS, mode);
@@ -442,7 +427,7 @@ int p_stat(const char* path, struct stat* buf)
442
427
  git_win32_path path_w;
443
428
  int len;
444
429
 
445
- if ((len = utf8_to_16_with_errno(path_w, path)) < 0)
430
+ if ((len = git_win32_path_from_utf8(path_w, path)) < 0)
446
431
  return -1;
447
432
 
448
433
  git_win32__path_trim_end(path_w, len);
@@ -462,7 +447,7 @@ int p_chdir(const char* path)
462
447
  {
463
448
  git_win32_path buf;
464
449
 
465
- if (utf8_to_16_with_errno(buf, path) < 0)
450
+ if (git_win32_path_from_utf8(buf, path) < 0)
466
451
  return -1;
467
452
 
468
453
  return _wchdir(buf);
@@ -472,7 +457,7 @@ int p_chmod(const char* path, mode_t mode)
472
457
  {
473
458
  git_win32_path buf;
474
459
 
475
- if (utf8_to_16_with_errno(buf, path) < 0)
460
+ if (git_win32_path_from_utf8(buf, path) < 0)
476
461
  return -1;
477
462
 
478
463
  return _wchmod(buf, mode);
@@ -483,7 +468,7 @@ int p_rmdir(const char* path)
483
468
  git_win32_path buf;
484
469
  int error;
485
470
 
486
- if (utf8_to_16_with_errno(buf, path) < 0)
471
+ if (git_win32_path_from_utf8(buf, path) < 0)
487
472
  return -1;
488
473
 
489
474
  error = _wrmdir(buf);
@@ -512,7 +497,7 @@ char *p_realpath(const char *orig_path, char *buffer)
512
497
  {
513
498
  git_win32_path orig_path_w, buffer_w;
514
499
 
515
- if (utf8_to_16_with_errno(orig_path_w, orig_path) < 0)
500
+ if (git_win32_path_from_utf8(orig_path_w, orig_path) < 0)
516
501
  return NULL;
517
502
 
518
503
  /* Note that if the path provided is a relative path, then the current directory
@@ -533,20 +518,17 @@ char *p_realpath(const char *orig_path, char *buffer)
533
518
  return NULL;
534
519
  }
535
520
 
536
- /* Convert the path to UTF-8. */
537
- if (buffer) {
538
- /* If the caller provided a buffer, then it is assumed to be GIT_WIN_PATH_UTF8
539
- * characters in size. If it isn't, then we may overflow. */
540
- if (git__utf16_to_8(buffer, GIT_WIN_PATH_UTF8, buffer_w) < 0)
541
- return NULL;
542
- } else {
543
- /* If the caller did not provide a buffer, then we allocate one for the caller
544
- * from the heap. */
545
- if (git__utf16_to_8_alloc(&buffer, buffer_w) < 0)
546
- return NULL;
521
+ if (!buffer && !(buffer = git__malloc(GIT_WIN_PATH_UTF8))) {
522
+ errno = ENOMEM;
523
+ return NULL;
547
524
  }
548
525
 
549
- /* Convert backslashes to forward slashes */
526
+ /* Convert the path to UTF-8. If the caller provided a buffer, then it
527
+ * is assumed to be GIT_WIN_PATH_UTF8 characters in size. If it isn't,
528
+ * then we may overflow. */
529
+ if (git_win32_path_to_utf8(buffer, buffer_w) < 0)
530
+ return NULL;
531
+
550
532
  git_path_mkposix(buffer);
551
533
 
552
534
  return buffer;
@@ -579,6 +561,7 @@ int p_snprintf(char *buffer, size_t count, const char *format, ...)
579
561
  return r;
580
562
  }
581
563
 
564
+ /* TODO: wut? */
582
565
  int p_mkstemp(char *tmp_path)
583
566
  {
584
567
  #if defined(_MSC_VER)
@@ -596,7 +579,7 @@ int p_access(const char* path, mode_t mode)
596
579
  {
597
580
  git_win32_path buf;
598
581
 
599
- if (utf8_to_16_with_errno(buf, path) < 0)
582
+ if (git_win32_path_from_utf8(buf, path) < 0)
600
583
  return -1;
601
584
 
602
585
  return _waccess(buf, mode);
@@ -610,8 +593,8 @@ int p_rename(const char *from, const char *to)
610
593
  int rename_succeeded;
611
594
  int error;
612
595
 
613
- if (utf8_to_16_with_errno(wfrom, from) < 0 ||
614
- utf8_to_16_with_errno(wto, to) < 0)
596
+ if (git_win32_path_from_utf8(wfrom, from) < 0 ||
597
+ git_win32_path_from_utf8(wto, to) < 0)
615
598
  return -1;
616
599
 
617
600
  /* wait up to 50ms if file is locked by another thread or process */
@@ -26,6 +26,14 @@ GIT_INLINE(DWORD) get_wc_flags(void)
26
26
  return flags;
27
27
  }
28
28
 
29
+ GIT_INLINE(void) git__set_errno(void)
30
+ {
31
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
32
+ errno = ENAMETOOLONG;
33
+ else
34
+ errno = EINVAL;
35
+ }
36
+
29
37
  /**
30
38
  * Converts a UTF-8 string to wide characters.
31
39
  *
@@ -36,10 +44,15 @@ GIT_INLINE(DWORD) get_wc_flags(void)
36
44
  */
37
45
  int git__utf8_to_16(wchar_t *dest, size_t dest_size, const char *src)
38
46
  {
47
+ int len;
48
+
39
49
  /* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to
40
50
  * turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's
41
51
  * length. MultiByteToWideChar never returns int's minvalue, so underflow is not possible */
42
- return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, dest, (int)dest_size) - 1;
52
+ if ((len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, dest, (int)dest_size) - 1) < 0)
53
+ git__set_errno();
54
+
55
+ return len;
43
56
  }
44
57
 
45
58
  /**
@@ -52,10 +65,15 @@ int git__utf8_to_16(wchar_t *dest, size_t dest_size, const char *src)
52
65
  */
53
66
  int git__utf16_to_8(char *dest, size_t dest_size, const wchar_t *src)
54
67
  {
68
+ int len;
69
+
55
70
  /* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to
56
71
  * turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's
57
72
  * length. WideCharToMultiByte never returns int's minvalue, so underflow is not possible */
58
- return WideCharToMultiByte(CP_UTF8, get_wc_flags(), src, -1, dest, (int)dest_size, NULL, NULL) - 1;
73
+ if ((len = WideCharToMultiByte(CP_UTF8, get_wc_flags(), src, -1, dest, (int)dest_size, NULL, NULL) - 1) < 0)
74
+ git__set_errno();
75
+
76
+ return len;
59
77
  }
60
78
 
61
79
  /**
@@ -76,17 +94,23 @@ int git__utf8_to_16_alloc(wchar_t **dest, const char *src)
76
94
  /* Length of -1 indicates NULL termination of the input string */
77
95
  utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, NULL, 0);
78
96
 
79
- if (!utf16_size)
97
+ if (!utf16_size) {
98
+ git__set_errno();
80
99
  return -1;
100
+ }
81
101
 
82
102
  *dest = git__malloc(utf16_size * sizeof(wchar_t));
83
103
 
84
- if (!*dest)
104
+ if (!*dest) {
105
+ errno = ENOMEM;
85
106
  return -1;
107
+ }
86
108
 
87
109
  utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, *dest, utf16_size);
88
110
 
89
111
  if (!utf16_size) {
112
+ git__set_errno();
113
+
90
114
  git__free(*dest);
91
115
  *dest = NULL;
92
116
  }
@@ -116,17 +140,23 @@ int git__utf16_to_8_alloc(char **dest, const wchar_t *src)
116
140
  /* Length of -1 indicates NULL termination of the input string */
117
141
  utf8_size = WideCharToMultiByte(CP_UTF8, dwFlags, src, -1, NULL, 0, NULL, NULL);
118
142
 
119
- if (!utf8_size)
143
+ if (!utf8_size) {
144
+ git__set_errno();
120
145
  return -1;
146
+ }
121
147
 
122
148
  *dest = git__malloc(utf8_size);
123
149
 
124
- if (!*dest)
150
+ if (!*dest) {
151
+ errno = ENOMEM;
125
152
  return -1;
153
+ }
126
154
 
127
155
  utf8_size = WideCharToMultiByte(CP_UTF8, dwFlags, src, -1, *dest, utf8_size, NULL, NULL);
128
156
 
129
157
  if (!utf8_size) {
158
+ git__set_errno();
159
+
130
160
  git__free(*dest);
131
161
  *dest = NULL;
132
162
  }
@@ -10,21 +10,6 @@
10
10
  #include <wchar.h>
11
11
  #include "common.h"
12
12
 
13
- /* Equal to the Win32 MAX_PATH constant. The maximum path length is 259
14
- * characters plus a NULL terminator. */
15
- #define GIT_WIN_PATH_UTF16 260
16
-
17
- /* Maximum size of a UTF-8 Win32 path. UTF-8 does have 4-byte sequences,
18
- * but they are encoded in UTF-16 using surrogate pairs, which takes up
19
- * the space of two characters. Two characters in the range U+0800 ->
20
- * U+FFFF take up more space in UTF-8 (6 bytes) than one surrogate pair
21
- * (4 bytes). */
22
- #define GIT_WIN_PATH_UTF8 (259 * 3 + 1)
23
-
24
- /* Win32 path types */
25
- typedef wchar_t git_win32_path[GIT_WIN_PATH_UTF16];
26
- typedef char git_win32_utf8_path[GIT_WIN_PATH_UTF8];
27
-
28
13
  /**
29
14
  * Converts a UTF-8 string to wide characters.
30
15
  *
@@ -67,28 +52,4 @@ int git__utf8_to_16_alloc(wchar_t **dest, const char *src);
67
52
  */
68
53
  int git__utf16_to_8_alloc(char **dest, const wchar_t *src);
69
54
 
70
- /**
71
- * Converts a UTF-8 Win32 path to wide characters.
72
- *
73
- * @param dest The buffer to receive the wide string.
74
- * @param src The UTF-8 string to convert.
75
- * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
76
- */
77
- GIT_INLINE(int) git_win32_path_from_utf8(git_win32_path dest, const char *src)
78
- {
79
- return git__utf8_to_16(dest, GIT_WIN_PATH_UTF16, src);
80
- }
81
-
82
- /**
83
- * Converts a wide Win32 path to UTF-8.
84
- *
85
- * @param dest The buffer to receive the UTF-8 string.
86
- * @param src The wide string to convert.
87
- * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure
88
- */
89
- GIT_INLINE(int) git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src)
90
- {
91
- return git__utf16_to_8(dest, GIT_WIN_PATH_UTF8, src);
92
- }
93
-
94
55
  #endif
@@ -9,6 +9,7 @@
9
9
  #define INCLUDE_w32_util_h__
10
10
 
11
11
  #include "utf-conv.h"
12
+ #include "path_w32.h"
12
13
 
13
14
  GIT_INLINE(bool) git_win32__isalpha(wchar_t c)
14
15
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugged
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.2
4
+ version: 0.21.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-17 00:00:00.000000000 Z
12
+ date: 2014-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -427,6 +427,8 @@ files:
427
427
  - vendor/libgit2/src/win32/map.c
428
428
  - vendor/libgit2/src/win32/mingw-compat.h
429
429
  - vendor/libgit2/src/win32/msvc-compat.h
430
+ - vendor/libgit2/src/win32/path_w32.c
431
+ - vendor/libgit2/src/win32/path_w32.h
430
432
  - vendor/libgit2/src/win32/posix.h
431
433
  - vendor/libgit2/src/win32/posix_w32.c
432
434
  - vendor/libgit2/src/win32/precompiled.c