0002-Add-support-for-File-lutimes-on-Windows.patch

Krzysztof Wilczynski, 10/19/2012 03:54 AM

Download (3.9 KB)

View differences:

file.c
92 92
#define chown(p, o, g)	rb_w32_uchown((p), (o), (g))
93 93
#undef utime
94 94
#define utime(p, t)	rb_w32_uutime((p), (t))
95
#undef lutime
96
#define lutime(p, t)	rb_w32_luutime((p), (t))
95 97
#undef link
96 98
#define link(f, t)	rb_w32_ulink((f), (t))
97 99
#undef unlink
win32/win32.c
6195 6195
}
6196 6196

  
6197 6197
/* License: Ruby's */
6198
typedef enum utime_mode utime_mode_t;
6199

  
6200
enum utime_mode {
6201
    M_SYMLINK_FOLLOW = 0,
6202
    M_SYMLINK_NOFOLLOW
6203
};
6204

  
6205
/* License: Ruby's */
6198 6206
static int
6199 6207
unixtime_to_filetime(time_t time, FILETIME *ft)
6200 6208
{
......
6208 6216

  
6209 6217
/* License: Ruby's */
6210 6218
static int
6211
wutime(const WCHAR *path, const struct utimbuf *times)
6219
wutime(const WCHAR *path, const struct utimbuf *times, utime_mode_t mode)
6212 6220
{
6213 6221
    HANDLE hFile;
6214 6222
    FILETIME atime, mtime;
......
6232 6240
	mtime = atime;
6233 6241
    }
6234 6242

  
6243
    int flags = FILE_FLAG_BACKUP_SEMANTICS;
6244

  
6245
    if (mode == M_SYMLINK_NOFOLLOW)
6246
        flags |= FILE_FLAG_OPEN_REPARSE_POINT;
6247

  
6235 6248
    RUBY_CRITICAL({
6236 6249
	const DWORD attr = GetFileAttributesW(path);
6237 6250
	if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
6238 6251
	    SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
6239 6252
	hFile = CreateFileW(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING,
6240
			    FILE_FLAG_BACKUP_SEMANTICS, 0);
6253
			    flags, 0);
6241 6254
	if (hFile == INVALID_HANDLE_VALUE) {
6242 6255
	    errno = map_errno(GetLastError());
6243 6256
	    ret = -1;
......
6258 6271

  
6259 6272
/* License: Ruby's */
6260 6273
int
6261
rb_w32_uutime(const char *path, const struct utimbuf *times)
6274
uutime_internal(const char *path, const struct utimbuf *time, utime_mode_t mode)
6262 6275
{
6263 6276
    WCHAR *wpath;
6264 6277
    int ret;
6265 6278

  
6266 6279
    if (!(wpath = utf8_to_wstr(path, NULL)))
6267 6280
	return -1;
6268
    ret = wutime(wpath, times);
6281
    ret = wutime(wpath, times, mode);
6269 6282
    free(wpath);
6270 6283
    return ret;
6271 6284
}
6272 6285

  
6273 6286
/* License: Ruby's */
6274 6287
int
6275
rb_w32_utime(const char *path, const struct utimbuf *times)
6288
utime_internal(const char *path, const struct utimbuf *times, utime_mode_t mode)
6276 6289
{
6277 6290
    WCHAR *wpath;
6278 6291
    int ret;
6279 6292

  
6280 6293
    if (!(wpath = filecp_to_wstr(path, NULL)))
6281 6294
	return -1;
6282
    ret = wutime(wpath, times);
6295
    ret = wutime(wpath, times, mode);
6283 6296
    free(wpath);
6284 6297
    return ret;
6285 6298
}
6286 6299

  
6287 6300
/* License: Ruby's */
6288 6301
int
6302
rb_w32_uutime(const char *path, const struct utimbuf *times)
6303
{
6304
    return uutime_internal(path, utimbuf, M_SYMLINK_FOLLOW);
6305
}
6306

  
6307
/* License: Ruby's */
6308
int
6309
rb_w32_utime(const char *path, const struct utimbuf *times)
6310
{
6311
    return utime_internal(path, utimbuf, M_SYMLINK_FOLLOW);
6312
}
6313

  
6314
/* License: Ruby's */
6315
int
6316
rb_w32_luutime(const char *path, const struct utimbuf *times)
6317
{
6318
    return uutime_internal(path, utimbuf, M_SYMLINK_NOFOLLOW);
6319
}
6320

  
6321
/* License: Ruby's */
6322
int
6323
rb_w32_lutime(const char *path, const struct utimbuf *times)
6324
{
6325
    return utime_internal(path, utimbuf, M_SYMLINK_NOFOLLOW);
6326
}
6327

  
6328
/* License: Ruby's */
6329
int
6289 6330
rb_w32_uchdir(const char *path)
6290 6331
{
6291 6332
    WCHAR *wpath;
6292
-