From 8dc689ce3897b6a11877ecf9140fec859f1b95a5 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 16 Nov 2013 17:50:56 +0200 Subject: [PATCH] Converted sys_unlink and sys_rmdir, got rid of pending deletion in w32proc.c. --- src/w32.c | 37 ++++++++++++++++++++++++++++++---- src/w32.h | 8 -------- src/w32proc.c | 56 --------------------------------------------------- 3 files changed, 33 insertions(+), 68 deletions(-) diff --git a/src/w32.c b/src/w32.c index 1ae0bb0d3d7..ac2878a95fd 100644 --- a/src/w32.c +++ b/src/w32.c @@ -4011,7 +4011,22 @@ sys_rename (char const *old, char const *new) int sys_rmdir (const char * path) { - return _rmdir (map_w32_filename (path, NULL)); + path = map_w32_filename (path, NULL); + + if (w32_unicode_filenames) + { + wchar_t path_w[MAX_PATH]; + + filename_to_utf16 (path, path_w); + return _wrmdir (path_w); + } + else + { + char path_a[MAX_PATH]; + + filename_to_ansi (path, path_a); + return _rmdir (path_a); + } } int @@ -4019,9 +4034,23 @@ sys_unlink (const char * path) { path = map_w32_filename (path, NULL); - /* On Unix, unlink works without write permission. */ - _chmod (path, 0666); - return _unlink (path); + if (w32_unicode_filenames) + { + wchar_t path_w[MAX_PATH]; + + filename_to_utf16 (path, path_w); + /* On Unix, unlink works without write permission. */ + _wchmod (path_w, 0666); + return _wunlink (path_w); + } + else + { + char path_a[MAX_PATH]; + + filename_to_ansi (path, path_a); + _chmod (path_a, 0666); + return _unlink (path_a); + } } static FILETIME utc_base_ft; diff --git a/src/w32.h b/src/w32.h index 80756e8e4ff..5e0f63d2433 100644 --- a/src/w32.h +++ b/src/w32.h @@ -103,12 +103,6 @@ typedef struct _child_process OVERLAPPED ovl_read; /* Used for async write operations on serial comm ports. */ OVERLAPPED ovl_write; - /* Input file, if any, for this subprocess. Should only be non-NULL - for async subprocesses. */ - char *input_file; - /* If non-zero, the subprocess input file is temporary and should be - deleted when the subprocess exits. */ - int pending_deletion; } child_process; #define MAXDESC FD_SETSIZE @@ -199,8 +193,6 @@ extern int pipe2 (int *, int); extern void set_process_dir (char *); extern int sys_spawnve (int, char *, char **, char **); extern void register_child (pid_t, int); -extern void record_infile (pid_t, char *); -extern void record_pending_deletion (char *); extern void sys_sleep (int); extern int sys_link (const char *, const char *); diff --git a/src/w32proc.c b/src/w32proc.c index 89748267bc6..de4e9103173 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -861,8 +861,6 @@ new_child (void) cp->pid = -1; cp->procinfo.hProcess = NULL; cp->status = STATUS_READ_ERROR; - cp->input_file = NULL; - cp->pending_deletion = 0; /* use manual reset event so that select() will function properly */ cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL); @@ -911,21 +909,6 @@ delete_child (child_process *cp) if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess == NULL) return; - /* Delete the child's temporary input file, if any, that is pending - deletion. */ - if (cp->input_file) - { - if (cp->pending_deletion) - { - if (unlink (cp->input_file)) - DebPrint (("delete_child.unlink (%s) failed, errno: %d\n", - cp->input_file, errno)); - cp->pending_deletion = 0; - } - xfree (cp->input_file); - cp->input_file = NULL; - } - /* reap thread if necessary */ if (cp->thrd) { @@ -1182,45 +1165,6 @@ register_child (pid_t pid, int fd) fd_info[fd].cp = cp; } -/* Record INFILE as an input file for process PID. */ -void -record_infile (pid_t pid, char *infile) -{ - child_process *cp; - - /* INFILE should never be NULL, since xstrdup would have signaled - memory full condition in that case, see callproc.c where this - function is called. */ - eassert (infile); - - cp = find_child_pid ((DWORD)pid); - if (cp == NULL) - { - DebPrint (("record_infile is unable to find pid %lu\n", pid)); - return; - } - - cp->input_file = infile; -} - -/* Mark the input file INFILE of the corresponding subprocess as - temporary, to be deleted when the subprocess exits. */ -void -record_pending_deletion (char *infile) -{ - child_process *cp; - - eassert (infile); - - for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) - if (CHILD_ACTIVE (cp) - && cp->input_file && xstrcasecmp (cp->input_file, infile) == 0) - { - cp->pending_deletion = 1; - break; - } -} - /* Called from waitpid when a process exits. */ static void reap_subprocess (child_process *cp) -- 2.39.2