* fhandler_disk_file.cc (fhandler_base::utimes_fs): Use existing handle if

fhandler has one.
* times.cc (utimes): Scan open fds for matching paths and use existing fhandler
if one exists.
This commit is contained in:
Christopher Faylor 2005-10-19 16:50:43 +00:00
parent b3982520d3
commit 5a90915d41
3 changed files with 50 additions and 18 deletions

View File

@ -1,3 +1,10 @@
2005-10-19 Christopher Faylor <cgf@timesys.com>
* fhandler_disk_file.cc (fhandler_base::utimes_fs): Use existing handle
if fhandler has one.
* times.cc (utimes): Scan open fds for matching paths and use existing
fhandler if one exists.
2005-10-19 Christopher Faylor <cgf@timesys.com>
* pinfo.cc (_pinfo::dup_proc_pipe): Make warning more severe by

View File

@ -865,20 +865,27 @@ fhandler_base::utimes_fs (const struct timeval *tvp)
{
FILETIME lastaccess, lastwrite;
struct timeval tmp[2];
bool closeit;
query_open (query_write_attributes);
if (!open_fs (O_BINARY, 0))
if (get_handle ())
closeit = false;
else
{
/* It's documented in MSDN that FILE_WRITE_ATTRIBUTES is sufficient
to change the timestamps. Unfortunately it's not sufficient for a
remote HPFS which requires GENERIC_WRITE, so we just retry to open
for writing, though this fails for R/O files of course. */
query_open (no_query);
if (!open_fs (O_WRONLY | O_BINARY, 0))
query_open (query_write_attributes);
if (!open_fs (O_BINARY, 0))
{
syscall_printf ("Opening file failed");
return -1;
/* It's documented in MSDN that FILE_WRITE_ATTRIBUTES is sufficient
to change the timestamps. Unfortunately it's not sufficient for a
remote HPFS which requires GENERIC_WRITE, so we just retry to open
for writing, though this fails for R/O files of course. */
query_open (no_query);
if (!open_fs (O_WRONLY | O_BINARY, 0))
{
syscall_printf ("Opening file failed");
return -1;
}
}
closeit = true;
}
if (nohandle ()) /* Directory query_open on 9x. */
@ -909,7 +916,8 @@ fhandler_base::utimes_fs (const struct timeval *tvp)
return -1;
}
close ();
if (closeit)
close ();
return 0;
}

View File

@ -22,6 +22,7 @@ details. */
#include "path.h"
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
#include "pinfo.h"
#include "hires.h"
#include "cygtls.h"
@ -445,21 +446,37 @@ extern "C" int
utimes (const char *path, const struct timeval *tvp)
{
int res = -1;
fhandler_base *fh;
path_conv win32 (path, PC_SYM_FOLLOW);
fhandler_base *fh = NULL;
bool fromfd = false;
if (!(fh = build_fh_name (path, NULL, PC_SYM_FOLLOW)))
goto error;
cygheap_fdenum cfd;
while (cfd.next () >= 0)
if (strcmp (cfd->get_win32_name (), win32) == 0)
{
fh = cfd;
fromfd = true;
break;
}
if (!fh)
{
if (!(fh = build_fh_name (path, NULL, PC_SYM_FOLLOW)))
goto error;
if (fh->error ())
{
debug_printf ("got %d error from build_fh_name", fh->error ());
set_errno (fh->error ());
}
else
res = fh->utimes (tvp);
}
delete fh;
error:
res = fh->utimes (tvp);
if (!fromfd)
delete fh;
error:
syscall_printf ("%d = utimes (%s, %p)", res, path, tvp);
return res;
}