* path.h (etc::change_possible): Revert the type to bool.

(etc::set_last_modified): Remove obsolete function.
* path.cc (etc::change_possible): Revert type to bool.
(etc::test_file_change): Do not test for negative values of change_possible and
do not set it to -res.
(etc::dir_changed): When the handle is NULL, call memset instead of
test_file_changed.  When the handle is invalid, return true.
(etc::file_changed): Remove unneeded check for !fn[n].
This commit is contained in:
Christopher Faylor 2003-01-21 05:07:28 +00:00
parent 14d304da97
commit d8cde3a3ee
5 changed files with 20 additions and 22 deletions

View File

@ -1,3 +1,14 @@
2003-01-21 Pierre Humblet <pierre.humblet@ieee.org>
* path.h (etc::change_possible): Revert the type to bool.
(etc::set_last_modified): Remove obsolete function.
* path.cc (etc::change_possible): Revert type to bool.
(etc::test_file_change): Do not test for negative values of
change_possible and do not set it to -res.
(etc::dir_changed): When the handle is NULL, call memset instead of
test_file_changed. When the handle is invalid, return true.
(etc::file_changed): Remove unneeded check for !fn[n].
2003-01-19 Christopher Faylor <cgf@redhat.com> 2003-01-19 Christopher Faylor <cgf@redhat.com>
* pwdgrp.h (etc): Move to path.h. * pwdgrp.h (etc): Move to path.h.
@ -41,7 +52,6 @@
(etc::file_changed): Use test_file_change to detect if file needs to be (etc::file_changed): Use test_file_change to detect if file needs to be
updated. updated.
* path.h (etc): Move class here from pwdgrp.h. * path.h (etc): Move class here from pwdgrp.h.
* uinfo.cc: Move etc:: functions to path.cc. Move pwdgrp functions * uinfo.cc: Move etc:: functions to path.cc. Move pwdgrp functions
here. here.
(pwdgrp::gets): Eliminate buf checks. Just check eptr and set lptr. (pwdgrp::gets): Eliminate buf checks. Just check eptr and set lptr.

View File

@ -3756,7 +3756,7 @@ out:
int etc::curr_ix = 0; int etc::curr_ix = 0;
/* Note that the first elements of the below arrays are unused */ /* Note that the first elements of the below arrays are unused */
signed char etc::change_possible[MAX_ETC_FILES + 1]; bool etc::change_possible[MAX_ETC_FILES + 1];
const char *etc::fn[MAX_ETC_FILES + 1]; const char *etc::fn[MAX_ETC_FILES + 1];
FILETIME etc::last_modified[MAX_ETC_FILES + 1]; FILETIME etc::last_modified[MAX_ETC_FILES + 1];
@ -3784,12 +3784,7 @@ etc::test_file_change (int n)
WIN32_FIND_DATA data; WIN32_FIND_DATA data;
bool res; bool res;
if (change_possible[n] < 0) if ((h = FindFirstFile (fn[n], &data)) == INVALID_HANDLE_VALUE)
{
res = true;
paranoid_printf ("fn[%d] %s, already marked changed", n, fn[n]);
}
else if ((h = FindFirstFile (fn[n], &data)) == INVALID_HANDLE_VALUE)
{ {
res = true; res = true;
memset (last_modified + n, 0, sizeof (last_modified[n])); memset (last_modified + n, 0, sizeof (last_modified[n]));
@ -3800,7 +3795,6 @@ etc::test_file_change (int n)
FindClose (h); FindClose (h);
res = CompareFileTime (&data.ftLastWriteTime, last_modified + n) > 0; res = CompareFileTime (&data.ftLastWriteTime, last_modified + n) > 0;
last_modified[n] = data.ftLastWriteTime; last_modified[n] = data.ftLastWriteTime;
change_possible[n] = -res;
debug_printf ("FindFirstFile succeeded"); debug_printf ("FindFirstFile succeeded");
} }
@ -3825,16 +3819,15 @@ etc::dir_changed (int n)
system_printf ("Can't open /etc for checking, %E", (char *) pwd, system_printf ("Can't open /etc for checking, %E", (char *) pwd,
changed_h); changed_h);
#endif #endif
for (int i = 1; i <= curr_ix; i++) memset (change_possible, true, sizeof (change_possible));
(void) test_file_change (i);
} }
if (changed_h == INVALID_HANDLE_VALUE) if (changed_h == INVALID_HANDLE_VALUE)
(void) test_file_change (n); /* semi-brute-force way */ change_possible[n] = true;
else if (WaitForSingleObject (changed_h, 0) == WAIT_OBJECT_0) else if (WaitForSingleObject (changed_h, 0) == WAIT_OBJECT_0)
{ {
(void) FindNextChangeNotification (changed_h); (void) FindNextChangeNotification (changed_h);
memset (change_possible, 1, sizeof change_possible); memset (change_possible, true, sizeof change_possible);
} }
} }
@ -3846,11 +3839,9 @@ bool
etc::file_changed (int n) etc::file_changed (int n)
{ {
bool res = false; bool res = false;
if (!fn[n]) if (dir_changed (n) && test_file_change (n))
res = true; res = true;
else if (dir_changed (n) && test_file_change (n)) change_possible[n] = false; /* Change is no longer possible */
res = true;
change_possible[n] = 0;
paranoid_printf ("fn[%d] %s res %d", n, fn[n], res); paranoid_printf ("fn[%d] %s res %d", n, fn[n], res);
return res; return res;
} }

View File

@ -213,13 +213,12 @@ int path_prefix_p (const char *path1, const char *path2, int len1) __attribute__
class etc class etc
{ {
static int curr_ix; static int curr_ix;
static signed char change_possible[MAX_ETC_FILES + 1]; static bool change_possible[MAX_ETC_FILES + 1];
static const char *fn[MAX_ETC_FILES + 1]; static const char *fn[MAX_ETC_FILES + 1];
static FILETIME last_modified[MAX_ETC_FILES + 1]; static FILETIME last_modified[MAX_ETC_FILES + 1];
static bool dir_changed (int); static bool dir_changed (int);
static int init (int, const char *); static int init (int, const char *);
static bool file_changed (int); static bool file_changed (int);
static void set_last_modified (int, FILETIME&);
static bool test_file_change (int); static bool test_file_change (int);
friend class pwdgrp; friend class pwdgrp;
}; };

View File

@ -59,7 +59,6 @@ public:
state = initializing; state = initializing;
return state == initializing; return state == initializing;
} }
void operator = (pwdgrp_state nstate) { state = nstate; }
bool isuninitialized () const { return state == uninitialized; } bool isuninitialized () const { return state == uninitialized; }
bool load (const char *); bool load (const char *);

View File

@ -452,7 +452,6 @@ pwdgrp::load (const char *posix_fname)
if (buf) if (buf)
free (buf); free (buf);
buf = NULL; buf = NULL;
fh = NULL;
res = false; res = false;
} }
else else