lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi Steve,

A small fix for your module (but necessary!). The "watch_for_file_changes" currently crash when there is several changes at the same time in the directory. It happened to me at the 3rd change, the 

if (outchars == 0) {
        throw_error(fc->L,"wide char conversion borked");

is called in file_change_thread. It appears that to iterate on the PFILE_NOTIFY_INFORMATION structures, it uses directly

next = pni->NextEntryOffset

as an offset. However, for more than 2 changes, it should sum the offset. As the 'next' variable must be kept for the while condition, I have fixed it by adding a variable offset which is the sum of the previous 'next' (or pni->NextEntryOffset):

static void file_change_thread(FileChangeParms *fc) { // background file monitor thread
  while (1) {
    int next,offset;
    DWORD bytes;
    // This fills in some gaps:
    if (! ReadDirectoryChangesW(lcb_handle(fc),lcb_buf(fc),lcb_bufsz(fc),
        fc->subdirs, fc->how, &bytes,NULL,NULL))  {
      throw_error(fc->L,"read dir changes failed");
    next = 0;
    offset = 0;
    do {
      int outchars;
      char outbuff[MAX_PATH];
      outchars = WideCharToMultiByte(
        get_encoding(), 0,
        pni->FileNameLength/2, // it's bytes, not number of characters!
      if (outchars == 0) {
        throw_error(fc->L,"wide char conversion borked");
      outbuff[outchars] = '\0';  // not null-terminated!
      next = pni->NextEntryOffset;
      offset += next;
    } while (next != 0);

I have another problem, that I haven't resolved yet, involving thread and message queue (when using GUI application) . I take a look and described it in a few.


Alexandre Rion
Fuel and Fire Department (MEYGU)
EADS / Airbus Military