Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:32:19+00:00 2026-05-27T09:32:19+00:00

I have the following (crude) function, which continually watches a directory for new files

  • 0

I have the following (crude) function, which continually watches a directory for new files and files being deleted, recording such changes. It correctly records all new files and directories, but doesn’t seem to react at all to files or directories being deleted.

It appears to be the read() call which doesn’t return as it should when files are being deleted, though it does for files being created.

The function is being called as one of two independent threads, though at present the other thread doesn’t do anything (just an empty, infinite loop as a placeholder).

void* watchfs(void* arg) {
    int infp, watch, length, i ;
    char buffer[EVENT_BUF_LEN] ;
    struct inotify_event* event ;

    if ((infp = inotify_init()) < 0) {
        fatal("inotify: Could not initialize") ;
    }

    watch = inotify_add_watch(infp, userdir, IN_CREATE | IN_DELETE) ;

    for (;;) {
        length = read(infp, buffer, EVENT_BUF_LEN) ;
        if (length < 0) {
            fatal("inotify: Could not read events") ;
        }

        i = 0 ;
        while (i < length) {
            event = (struct inotify_event*) &buffer[i] ;

            if (event->len) {
                if (event->mask & IN_CREATE) {
                    if (event->mask & IN_ISDIR) {
                        record(LOG_FILESYS, "New directory created") ;
                    } else {
                        record(LOG_FILESYS, "New file created") ;
                    }
                } else if (event->mask & IN_DELETE) {
                    if (event->mask & IN_ISDIR) {
                        record(LOG_FILESYS, "Directory deleted") ;
                    } else {
                        record(LOG_FILESYS, "File deleted") ;
                    }
                }
            }

            i += EVENT_SIZE + event->len ;
        }
    }

    inotify_rm_watch(infp, watch) ;
    close(infp) ;

    return 0 ;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:32:20+00:00Added an answer on May 27, 2026 at 9:32 am

    Finally figured out what is going on. Linux, or perhaps Gnome, doesn’t actually delete files but simply moves them around. Even when a file is simply renamed it is apparently moved somewhere, then a new file with the new name is moved into the folder from somewhere else (a temp folder somewhere?). The rm command actually deletes a file and my code registers that as an IN_DELETE event as expected. Deleting files or directories in Gnome however registers as IN_MOVED_TO, while renaming registers as IN_MOVED_TO followed by IN_MOVED_FROM.

    I thought I had checked for this as one of the first things, but clearly not well enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function which does a crude job of parsing an XML
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following Code Block Which I tried to optimize in the Optimized section
I have a test results database which has the following three tables along with
I have the following Infragistics WedDataGrid (version 2.9.2), and JavaScript function. The first column
I had a model customer, which I have generated using the following rails g
I have the following code snippet : function getCheckListTaskWithId(id){ var tempTask = db.readTransaction(function (tx)
i have following entities as you see BudgetPost has a composite primary key which
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.