Giter Club home page Giter Club logo

Comments (7)

dsoprea avatar dsoprea commented on June 30, 2024

Sure. We never accounted for that. Can you make the change or do you want
to wait on me?

Dustin

On Aug 24, 2016 12:37 PM, "vaniatoperich" [email protected] wrote:

If you watch a folder and you rename the folder within that folder, event
will not update the watch, if will keep on using old watch_path and
filenames changed in that watch path will use old watch path:

Here is Renaming of the folder:
DEBUG 2016-08-24 16:35:13,717 (_INOTIFY_EVENT(wd=1, mask=1073741888,
cookie=174440, len=16), ['IN_MOVED_FROM', 'IN_ISDIR'],
b'/shared/media/content/Movies', b'VBH Demo')
DEBUG 2016-08-24 16:35:13,717 (_INOTIFY_EVENT(wd=1, mask=1073741952,
cookie=174440, len=32), ['IN_MOVED_TO', 'IN_ISDIR'],
b'/shared/media/content/Movies', b'VBH Demo Renamed')
DEBUG 2016-08-24 16:35:13,717 (_INOTIFY_EVENT(wd=2, mask=2048, cookie=0,
len=0), ['IN_MOVE_SELF'], b'/shared/media/content/Movies/VBH Demo', b'')

And here is toucing the file in that new folder:
DEBUG 2016-08-24 16:36:55,914 (_INOTIFY_EVENT(wd=2, mask=256, cookie=0,
len=16), ['IN_CREATE'], b'/shared/media/content/Movies/VBH Demo',
b'TESTFILE')
DEBUG 2016-08-24 16:36:55,915 (_INOTIFY_EVENT(wd=2, mask=32, cookie=0,
len=16), ['IN_OPEN'], b'/shared/media/content/Movies/VBH Demo',
b'TESTFILE')
DEBUG 2016-08-24 16:36:55,915 (_INOTIFY_EVENT(wd=2, mask=4, cookie=0,
len=16), ['IN_ATTRIB'], b'/shared/media/content/Movies/VBH Demo',
b'TESTFILE')
DEBUG 2016-08-24 16:36:55,915 (_INOTIFY_EVENT(wd=2, mask=8, cookie=0,
len=16), ['IN_CLOSE_WRITE'], b'/shared/media/content/Movies/VBH Demo',
b'TESTFILE')

As you can see, watch path is not changed to VBH Demo Renamed, it stayed
in VBH Demo.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#19, or mute the thread
https://github.com/notifications/unsubscribe-auth/AArrajufSycWohzEES3o7Hq2f14_rhUNks5qjHNlgaJpZM4JsNXv
.

from pyinotify.

vaniatoperich avatar vaniatoperich commented on June 30, 2024

I guess like this?:

                elif header.mask & inotify.constants.IN_MOVED_FROM:

                    self.__i.remove_watch(full_path, superficial=True)
                elif header.mask & inotify.constants.IN_MOVED_TO:

                    self.__i.add_watch(full_path, self.__mask)

from pyinotify.

dsoprea avatar dsoprea commented on June 30, 2024

This needs to stay open, @vaniatoperich. It's a bug and affects more than just you. Though I'd appreciate it if you took a look at it (sorry, I didn't have a chance to respond yesterday), it'll have to be fixed by someone.

from pyinotify.

vaniatoperich avatar vaniatoperich commented on June 30, 2024

Ah. Sorry. Missunderstanding. I did look into it and I posted the code that works for me (At least that seems so, but I am not sure if you agree with the approach? Please tell me what I can do to help?

from pyinotify.

vaniatoperich avatar vaniatoperich commented on June 30, 2024

Here is full code:

class InotifyTree(object):
    def __init__(self, path, mask=inotify.constants.IN_ALL_EVENTS, 
                 block_duration_s=_DEFAULT_EPOLL_BLOCK_DURATION_S):

        self.__root_path = path

        # No matter what we actually received as the mask, make sure we have 
        # the minimum that we require to curate our list of watches.
        self.__mask = mask | \
                        inotify.constants.IN_ISDIR | \
                        inotify.constants.IN_CREATE | \
                        inotify.constants.IN_DELETE

        self.__i = Inotify(block_duration_s=block_duration_s)

        self.__load_tree(path)

    def __load_tree(self, path):
        _LOGGER.debug("Adding initial watches on tree: [%s]", path)

        q = [path]
        while q:
            current_path = q[0]
            del q[0]

            self.__i.add_watch(current_path, self.__mask)

            for filename in os.listdir(current_path):
                entry_filepath = os.path.join(current_path, filename)
                if os.path.isdir(entry_filepath) is False:
                    continue

                q.append(entry_filepath)

    def event_gen(self):
        """This is a secondary generator that wraps the principal one, and 
        adds/removes watches as directories are added/removed.
        """

        for event in self.__i.event_gen():
            if event is not None:
                (header, type_names, path, filename) = event

                if header.mask & inotify.constants.IN_ISDIR:
                    full_path = os.path.join(path, filename)

                    if header.mask & inotify.constants.IN_CREATE:
                        _LOGGER.debug("A directory has been created. We're "
                                      "adding a watch on it (because we're "
                                      "being recursive): [%s]", full_path)

                        self.__i.add_watch(full_path, self.__mask)
                    elif header.mask & inotify.constants.IN_DELETE:
                        _LOGGER.debug("A directory has been removed. We're "
                                      "being recursive, but it would have "
                                      "automatically been deregistered: [%s]", 
                                      full_path)

                        # The watch would've already been cleaned-up internally.
                        self.__i.remove_watch(full_path, superficial=True)
                    elif header.mask & inotify.constants.IN_MOVED_FROM:
                        _LOGGER.debug("A directory has been renamed. We're "
                                      "being recursive, but it would have "
                                      "automatically been deregistered: [%s]",
                                      full_path)

                        self.__i.remove_watch(full_path, superficial=True)
                    elif header.mask & inotify.constants.IN_MOVED_TO:
                        _LOGGER.debug("A directory has been renamed. We're "
                                      "adding a watch on it (because we're "
                                      "being recursive): [%s]", full_path)

                        self.__i.add_watch(full_path, self.__mask)

            yield event

from pyinotify.

dsoprea avatar dsoprea commented on June 30, 2024

It looks great. Please fork and submit it as a PR so that I can more formally review it.

from pyinotify.

dsoprea avatar dsoprea commented on June 30, 2024

@vaniatoperich Bump. Can you do this? It'll be five-minutes of work on your part.

from pyinotify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.