windows: fix `copy-file' changes

This commit is contained in:
Matthew Flatt 2011-09-19 14:25:44 -06:00
parent 76e55071b0
commit df43d90513
3 changed files with 21 additions and 11 deletions

View File

@ -215,7 +215,7 @@ Scheme_Config *scheme_init_error_escape_proc(Scheme_Config *config)
%- = skip int %- = skip int
%L = line number as intptr_t, -1 means no line %L = line number as intptr_t, -1 means no line
%e = error number for strerror()/FormatMessage() %e = error number for strerror()
%E = error number for platform-specific error string %E = error number for platform-specific error string
%Z = potential platform-specific error number; additional char* %Z = potential platform-specific error number; additional char*
is either NULL or a specific error message is either NULL or a specific error message
@ -223,6 +223,8 @@ Scheme_Config *scheme_init_error_escape_proc(Scheme_Config *config)
or error number for scheme_hostname_error() or error number for scheme_hostname_error()
%m = boolean then error number like %e, which %m = boolean then error number like %e, which
is used only if the boolean is 1 is used only if the boolean is 1
%M = boolean then error number like %E, which
is used only if the boolean is 1
*/ */
static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list args, char **_s) static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list args, char **_s)
@ -275,6 +277,7 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list
break; break;
case 'N': case 'N':
case 'm': case 'm':
case 'M':
ints[ip++] = mzVA_ARG(args, int); ints[ip++] = mzVA_ARG(args, int);
ints[ip++] = mzVA_ARG(args, int); ints[ip++] = mzVA_ARG(args, int);
break; break;
@ -407,6 +410,7 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list
case 'e': case 'e':
case 'm': case 'm':
case 'E': case 'E':
case 'M':
case 'Z': case 'Z':
case 'N': case 'N':
{ {
@ -417,6 +421,10 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list
none = !ints[ip++]; none = !ints[ip++];
type = 'e'; type = 'e';
he = 0; he = 0;
} else if (type == 'M') {
none = !ints[ip++];
type = 'E';
he = 0;
} else if (type == 'N') { } else if (type == 'N') {
he = ints[ip++]; he = ints[ip++];
type = 'E'; type = 'E';

View File

@ -3967,7 +3967,7 @@ static Scheme_Object *copy_file(int argc, Scheme_Object **argv)
#endif #endif
scheme_raise_exn(pre_exists ? MZEXN_FAIL_FILESYSTEM_EXISTS : MZEXN_FAIL_FILESYSTEM, scheme_raise_exn(pre_exists ? MZEXN_FAIL_FILESYSTEM_EXISTS : MZEXN_FAIL_FILESYSTEM,
"copy-file: %s; cannot copy: %q to: %q%s%m%s", "copy-file: %s; cannot copy: %q to: %q%s%M%s",
reason, reason,
filename_for_error(argv[0]), filename_for_error(argv[0]),
filename_for_error(argv[1]), filename_for_error(argv[1]),

View File

@ -4125,8 +4125,10 @@ scheme_do_open_input_file(char *name, int offset, int argc, Scheme_Object *argv[
if (fd == INVALID_HANDLE_VALUE) { if (fd == INVALID_HANDLE_VALUE) {
if (err) { if (err) {
int errv;
errv = GetLastError();
*err = "cannot open source file"; *err = "cannot open source file";
*eerrno = GetLastError(); *eerrno = errv;
} else } else
filename_exn(name, "cannot open input file", filename, GetLastError()); filename_exn(name, "cannot open input file", filename, GetLastError());
return NULL; return NULL;
@ -4397,9 +4399,9 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv
NULL); NULL);
if (fd == INVALID_HANDLE_VALUE) { if (fd == INVALID_HANDLE_VALUE) {
int err; int errv;
err = GetLastError(); errv = GetLastError();
if ((err == ERROR_ACCESS_DENIED) && (existsok < -1)) { if ((errv == ERROR_ACCESS_DENIED) && (existsok < -1)) {
/* Delete and try again... */ /* Delete and try again... */
if (DeleteFileW(WIDE_PATH(filename))) { if (DeleteFileW(WIDE_PATH(filename))) {
fd = CreateFileW(WIDE_PATH(filename), fd = CreateFileW(WIDE_PATH(filename),
@ -4410,17 +4412,17 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv
0, 0,
NULL); NULL);
if (fd == INVALID_HANDLE_VALUE) if (fd == INVALID_HANDLE_VALUE)
err = GetLastError(); errv = GetLastError();
} else { } else {
scheme_raise_exn(MZEXN_FAIL_FILESYSTEM, scheme_raise_exn(MZEXN_FAIL_FILESYSTEM,
"%s: error deleting \"%q\" (%E)", "%s: error deleting \"%q\" (%E)",
name, filename, GetLastError()); name, filename, GetLastError());
return NULL; return NULL;
} }
} else if (err == ERROR_FILE_EXISTS) { } else if (errv == ERROR_FILE_EXISTS) {
if (err) { if (err) {
*err = "destination already exists"; *err = "destination already exists";
*eerrno = err; *eerrno = errv;
} else } else
scheme_raise_exn(MZEXN_FAIL_FILESYSTEM_EXISTS, scheme_raise_exn(MZEXN_FAIL_FILESYSTEM_EXISTS,
"%s: file \"%q\" exists", name, filename); "%s: file \"%q\" exists", name, filename);
@ -4430,9 +4432,9 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv
if (fd == INVALID_HANDLE_VALUE) { if (fd == INVALID_HANDLE_VALUE) {
if (err) { if (err) {
*err = "cannot open destination"; *err = "cannot open destination";
*eerrno = err; *eerrno = errv;
} else } else
filename_exn(name, "cannot open output file", filename, err); filename_exn(name, "cannot open output file", filename, errv);
return NULL; return NULL;
} }
} }