在Windows操作系统中,MS提供ReadDirectoryChangesW和FindFirstChangeNotification API来检测新文件或修改过的文件,Mac OSX是否也提供相同的功能?
我想编写一个OSX(Snow Leopard)应用程序,它可以在特定目录中的文件发生更改时接收通知,并且我希望访问已更改的特定文件的路径.
我知道我可以用做这一点File System Events
还是kqueue
.前者没有提供更改哪个特定文件的详细信息(要求我构建我正在观看的目录的快照,然后扫描它以找出更改的文件).后者不支持递归观看(要求我以递归方式将监视添加到父目录中的每个文件和目录).
我已经找到了可以为我处理快照/递归乐趣的库,但找不到任何库.UKKQueue
对于低级别的kqueue
东西看起来像是一个很好的包装器,但似乎没有做递归.同样的GTMFileSystemKQueue
.SCEvents
看起来像一个很好的包装,File System Events
但似乎没有找到更改的特定文件.
是否有一个库可以满足我的要求并且适合这些技术的objc项目?
这让我很伤心,我不确定我知道如何调试它。
我正在使用 Mac FSEvents API 来监视文件系统上的给定文件夹。但是,有时,某些文件夹会停止发送任何通知事件。到目前为止,这仅发生在 ~/Dropbox 中的文件夹中,并且只影响了我的应用程序的少数用户(并且也经常影响我)。
疯狂的部分是“治愈”文件系统的方法是:
mv ~/Dropbox/some/stuck/folder ~/Dropbox/some/stuck/folder.0
mkdir ~/Dropbox/some/stuck/folder
mv ~/Dropbox/some/stuck/folder.0/* ~/Dropbox/some/stuck/folder/
rmdir ~/Dropbox/some/stuck/folder.0
Run Code Online (Sandbox Code Playgroud)
运行这些命令后,文件夹会解开并开始发送事件!需要尝试几次才能找到哪个父文件夹是罪魁祸首,但它始终是 Dropbox 中的某个文件夹。(退出 Dropbox 或重新启动并不能治愈它。)
我在我的代码中没有做任何特别的事情。监控开始使用:
FSEventStreamContext context;
context.version = 0;
context.info = self;
context.retain = NULL;
context.release = NULL;
context.copyDescription = NULL;
_streamRef = FSEventStreamCreate(nil,
(FSEventStreamCallback)FSMonitorEventStreamCallback,
&context,
(CFArrayRef)paths,
kFSEventStreamEventIdSinceNow,
0.25,
kFSEventStreamCreateFlagUseCFTypes);
if (!_streamRef) {
NSLog(@"Failed to start monitoring of %@ (FSEventStreamCreate error)", _path);
}
FSEventStreamScheduleWithRunLoop(_streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
if (!FSEventStreamStart(_streamRef)) {
NSLog(@"Failed to start monitoring of %@ (FSEventStreamStart error)", _path);
} …
Run Code Online (Sandbox Code Playgroud) 您好:在构建项目时,我收到此错误:
2017-04-13 12:05 gulp[64643] (FSEvents.framework) FSEventStreamStart: ERROR: FSEvents_connect() => (ipc/send) invalid destination port (268435459)
Run Code Online (Sandbox Code Playgroud)
在吞咽过程结束时跟着这个[我不知道它们是否相关]
Message:
Command failed: /Users/toddpage/Code/RollKall-Coordinator-Portal/node_modules/node-notifier/vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Gulp notification" -message "Finished Script compilation" -appIcon "/Users/toddpage/Code/RollKall-Coordinator-Portal/node_modules/gulp-notify/assets/gulp.png"
Details:
killed: false
code: null
signal: SIGABRT
cmd: /Users/toddpage/Code/RollKall-Coordinator-Portal/node_modules/node-notifier/vendor/terminal-notifier.app/Contents/MacOS/terminal-notifier -title "Gulp notification" -message "Finished Script compilation" -appIcon "/Users/toddpage/Code/RollKall-Coordinator-Portal/node_modules/gulp-notify/assets/gulp.png"
Run Code Online (Sandbox Code Playgroud)
我已经撤消了可能导致此问题的任何代码更改,并重建了该项目,但我仍然收到此错误.任何帮助都会受到高度赞赏.
谢谢!
我在使用 macOS 框架 FSEvents 时遇到问题:当我调用FSEventStreamCreate
并传递kFSEventStreamEventIdSinceNow
“since”参数时,我仍然会收到kFSEventStreamEventFlagItemCreated
在创建和计划流之前几秒钟已生成的文件的事件。
NSArray* paths = createDummyFilesOnFileSystem();
sleepForFiveSeconds();
CFRunLoopRef runLoop = ...;
FSEventStreamContext context = ...;
CFTimeInterval latency = 0.5;
FSEventStreamCreateFlags streamCreateFlags =
kFSEventStreamCreateFlagUseCFTypes |
kFSEventStreamCreateFlagNoDefer |
kFSEventStreamCreateFlagWatchRoot |
kFSEventStreamCreateFlagFileEvents;
FSEventStreamRef stream = FSEventStreamCreate(NULL,
&fsEventCallback,
&context,
(__bridge CFArrayRef) paths,
kFSEventStreamEventIdSinceNow,
latency,
streamCreateFlags);
FSEventStreamScheduleWithRunLoop(stream, runLoop, kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
Run Code Online (Sandbox Code Playgroud)
我可以做些什么来避免收到kFSEventStreamEventFlagItemCreated
之前创建的那些文件的通知,或者我可以通过任何方式过滤掉这些文件(例如通过查看其他标志)?我已经尝试最初刷新流并传递FSEventsGetCurrentEventId()
since参数,但这也没有帮助。
谢谢!
我每次都会收到此消息npm install
:
> fsevents@1.2.4 install /Users/USERNAME/URL/TO/GULP/FILE/node_modules/fsevents\n> node install\n\n[fsevents] Success: "/Users/USERNAME/URL/TO/GULP/FILE/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed\nPass --update-binary to reinstall or --build-from-source to recompile\n\n> node-sass@3.13.1 install /Users/USERNAME/URL/TO/GULP/FILE/node_modules/node-sass\n> node scripts/install.js\n\nDownloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/darwin-x64-57_binding.node\nCannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/darwin-x64-57_binding.node":\n\nHTTP error 404 Not Found\n\nHint: If github.com is not accessible in your location\n try setting a proxy via HTTP_PROXY, e.g.\n\n export HTTP_PROXY=http://example.com:1234\n\nor configure npm proxy via\n\n npm config set proxy http://example.com:8080\n\n> node-sass@3.13.1 postinstall /Users/USERNAME/URL/TO/GULP/FILE/node_modules/node-sass\n> node scripts/build.js\n\nBuilding: /usr/local/bin/node /Users/USERNAME/URL/TO/GULP/FILE/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=\ngyp info it worked if it …
Run Code Online (Sandbox Code Playgroud) 所以我运行命令 npm install -D webpack
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v68-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for fsevents@1.2.7 and node@12.0.0-pre (node-v68 ABI, unknown) (falling back to source compile with node-gyp)
...
../../nan/nan_implementation_12_inl.h:356:58: error: expected '(' for function-style cast or type construction
return v8::StringObject::New(value).As<v8::StringObject>();
~~~~~~~~~~~~~~~~^
../../nan/nan_implementation_12_inl.h:356:60: error: expected expression
return v8::StringObject::New(value).As<v8::StringObject>();
^
../fsevents.cc:43:32: error: no template named 'Handle' in namespace 'v8'
static void Initialize(v8::Handle<v8::Object> exports);
~~~~^
...
../fsevents.cc:76:16: error: variable has incomplete …
Run Code Online (Sandbox Code Playgroud) 我知道有多个线程讨论NFS安装卷和文件修改监视问题。由于大多数讨论都是旧的,有些是 8 年前的,所以我的目标是编译一些并再次提出它们,以检查你们用来处理这些问题的最新解决方案是什么。
核心问题
Linux 依赖于inotify
一个内核子系统,在文件被修改(更改/删除)时生成事件,而这些事件最常被开发人员工具用来监视文件以触发某些任务。核心问题是,当您通过 NFS 协议共享卷/文件夹时,它不会生成事件,因此工具需要使用轮询方法而不是基于事件触发。
轮询方法通常会产生多个问题,例如 CPU 使用率高、文件更改导致任务触发延迟等。
一些观看工具:
热门话题
不错的解决方案尝试
我当前的挑战
我们使用 macOS 作为主机,使用 Vagrant(提供者 Virtualbox)和 Alpine Linux 作为来宾,以及用于服务的 Docker 容器(Node、NGINX...)来运行我们的开发环境,除了以下情况之外,所有设置都运行顺利:前端开发人员需要使用 webpack watch 功能来监视文件修改。它适用于轮询,但有 3-10 秒的延迟。
关于如何解决这个问题有任何更新或建议吗?
我创建了一个 github 操作来在推送时部署代码。
安装软件包时会导致此错误。
Run npm i --no-optional && cd client && npm i --no-optional && cd ..
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! notsup Valid OS: darwin
npm ERR! notsup Valid Arch: any
npm ERR! notsup Actual OS: linux
npm ERR! notsup Actual …
Run Code Online (Sandbox Code Playgroud) 我刚刚购买了 MacBook M2 Pro,并尝试使用 nodev19.6.0
和 npm运行我的旧 Vue 项目6.14.18
。在进行 npm 安装时,我遇到了 2 个错误,这似乎与使用 和node-gyp
等其他软件包进行构建有关。fibers@5.0.3
fsevents@1.2.9
> fibers@5.0.3 install /Users/user1/Projects/project1/frontend/node_modules/fibers
> node build.js || nodejs build.js
CXX(target) Release/obj.target/fibers/src/fibers.o
../src/fibers.cc:27:65: error: no member named 'kFinalizer' in 'v8::WeakCallbackType'
handle.SetWeak(val, WeakCallbackShim<F, P>, WeakCallbackType::kFinalizer);
~~~~~~~~~~~~~~~~~~^
1 error generated.
make: *** [Release/obj.target/fibers/src/fibers.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/user1/.nvm/versions/node/v19.6.0/lib/node_modules/npm/node_modules/npm-lifecycle/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack at ChildProcess.emit …
Run Code Online (Sandbox Code Playgroud) fsevents ×10
macos ×3
node-gyp ×3
node.js ×3
npm ×3
browser-sync ×1
cocoa ×1
docker ×1
fibers ×1
file ×1
filesystems ×1
gulp ×1
inotify ×1
ipc ×1
kqueue ×1
linux ×1
objective-c ×1
vagrant ×1
virtualbox ×1
webpack ×1