<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Guten Abend, die Herren,<div><br></div><div>ich beschäftige mich seit kurzem mit Python und bastele gerade</div><div>ein Tool, das das Modul MacFSEvents verwendet:</div><div><br></div><div><a href="https://github.com/malthe/macfsevents">https://github.com/malthe/macfsevents</a></div><div><br></div><div>Ich habe in dem Modul einen Fehler gefunden, der im Python-Teil</div><div>der Implementierung zu stecken scheint, und wäre dankbar, wenn</div><div>mich jemand bei der Fehlerbehebung unterstützen könnte.</div><div><br></div><div>Gerne würde ich auch einen Dienstleister dafür buchen, wenn</div><div>sich also jemand von Euch dazu berufen fühlt, wäre das klasse.</div><div><br></div><div>Das Problem gestaltet sich wie folgt:</div><div><br></div><div></div><blockquote type="cite"><div>When I watch a folder with subdirectories inside it and then<br>create a new subdirectory or file inside the watched folder,<br>all the other, already existing but still unchanged subdirectories<br>get the fsevent mask 256, which means created.<br><br>E.g. if this is the folder I watch, incl. subdirs:<br><br><img id="1725880b-4327-4ce4-a9a0-802a9dfc47f9" height="167" width="603" apple-width="yes" apple-height="yes" src="cid:FB3F1278-2CA6-4888-847D-2A2E1E2A1E0B"><br><br><br>Then I copy the file 1.png into the test folder:<br><br><img id="a78032a8-5da9-417d-a285-48bd4eaab026" height="167" width="603" apple-width="yes" apple-height="yes" src="cid:B9680013-A314-43EF-B31E-6336D6FA7088"><br><br>The events I receive, now, are:<br>---------------<br>file name: /test/1.png<br>Mask: 256, Cookie: None<br>---------------<br>file name: test/subdir2<br>Mask: 256, Cookie: None<br>---------------<br>file name: /test/subdir3<br>Mask: 256, Cookie: None<br>---------------<br>file name: /est/subdir1<br>Mask: 256, Cookie: None<br><br>This happens only the first time I copy something into a folder<br>after I start your module.<br><br>To me it looks as if your tool does the following:<br><br>The first time I copy something into a folder, your tool lists its<br>contents and keeps a reflection of that in memory.<br>As macfsevents doesn't know what the directory listing looked<br>like before the initial event, it marks all contained folders as<br>created (256). If there are files inside a folder, they only receive<br>an event if they are really changed.<br></div></blockquote><div><br></div>Es sieht so aus, als wenn in diesem Code:<div><br></div><div><a href="https://github.com/malthe/macfsevents/blob/master/fsevents.py">https://github.com/malthe/macfsevents/blob/master/fsevents.py</a></div><div><br></div><div>irgendwo ein Problem steckt, das zu dem oben beschriebenen</div><div>Verhalten führt.</div><div><br></div><div>Ein paar Vermutungen meinerseits habe ich dem Entwickler</div><div>geschickt:</div><div><br></div><div><blockquote type="cite">it's a bit hard for me to understand how your code works (I am fairly new<br>to Python), but at least I got a rough idea, now.<br><br>As far as I can see, the c file _fsevents.c seems to be okay<br>(<a href="https://github.com/malthe/macfsevents/blob/master/_fsevents.c">https://github.com/malthe/macfsevents/blob/master/_fsevents.c</a>).<br><br>The issue seems to be in fsevents.py<br>(https://github.com/malthe/macfsevents/blob/master/fsevents.py),<br>where you snapshot the filesystem to compare fsevents to changes<br>in the filesystem.<br><br>This seems to happen in the class<br><br>FileEventCallback<br><br>I am not exactly sure which part of the class really causes the issue,<br>but here are some ideas:<br><br>In line 165 and 166 it says:<br><br>               else:<br>                   event = FileEvent(IN_CREATE, None, filename)<br><br>As far as I can see, this would trigger a "created" event for all<br>folders in the current directory, and snapshoting the directories<br>right after doesn't delete the event.<br>Can this cause the issue?<br><br>In lines 168 and 169 it says:<br><br>if os.path.isdir(filename):<br>                   self.snapshot(filename)<br><br>If this triggers the creation of the "created" event, could it be an<br>issue, that this happens much later than the snapshot of the<br>normal files?<br><br>From line 179 on you define the function snapshot:<br><br>   def snapshot(self, path):<br>       path = os.path.realpath(path)<br>       refs = self.snapshots<br>       refs[path] = {}<br><br>       for root, dirs, files in os.walk(path):<br>           entry = refs[root]<br>           for filename in files:<br>               try:<br>                   entry[filename] = os.stat(os.path.join(root, filename))<br>               except OSError:<br>                   continue<br>           for directory in dirs:<br>               refs[os.path.join(root, directory)] = {}<br><br>       if os.path.isdir(path):<br>           refs[os.path.join(root, path)] = {}<br>           for name in os.listdir(os.path.join(root, path)):<br>               try:<br>                   refs[path][name] = os.stat(os.path.join(path, name))<br>               except OSError:<br>                   pass<br><br>There are a couple of things which are not obvious to me inside<br>this function, but as I said, I am fairly new to Python.<br><br>Why is there a for loop for root, dirs and files, but instead of<br>dealing with dirs inside this loop, you just create an empty<br>dictionary for refs and start an if block on the same level<br>right after?<br><br>If you could have a look at these things, that would be great!<br><br>As this is your code, it might be faster for you to fix it than<br>for me. Especially if we consider the level of expertise :-)<br></blockquote><div><br></div><div>Auch wenn sich der Entwickler noch einmal bei mir melden sollte,</div><div>so scheint er aktuell keine Zeit zu haben, sich mit der Materie</div><div>zu beschäftigen, und ich wäre recht dankbar, wenn mir jemand</div><div>mindestens bei diesem Teil, evtl. auch an anderen Stellen in</div><div>meinem aktuellen Projekt Hilfe leisten könnte.</div><div><br></div><div>Wenn also jemand Zeit für ein kleines Projekt hat, würde ich</div><div>mich sehr über eine Rückmeldung freuen.</div><div><br></div><div>Schöne Grüße und noch ein paar schöne Karnevalstage,</div><div><br></div><div>André Aulich</div><div><br><div apple-content-edited="true">--<br>André Aulich<br>Digital Asset Management & Workflow Automation<br><br>phone:<span class="Apple-tab-span" style="white-space:pre">  </span>+49 (0)221 - 99 81 545<br>mobile:<span class="Apple-tab-span" style="white-space:pre">     </span>+49 (0)173 - 25 17 719<br><br>mail:<span class="Apple-tab-span" style="white-space:pre">     </span><a href="mailto:info@andre-aulich.de">info@andre-aulich.de</a><br>web:<span class="Apple-tab-span" style="white-space:pre">  </span>www.andre-aulich.de<br><br>Hatzfeldstr. 6<br>51069 Köln<br>Germany<br></div><br></div></div></body></html>