29 #include <nsComponentManagerUtils.h>
30 #include <sys/inotify.h>
73 NS_ASSERTION(NS_SUCCEEDED(rv),
"ERROR: Could not cleanup inotify!");
84 for (descNext = descBegin; descNext != descEnd; ++descNext) {
85 inotify_rm_watch(mInotifyFileDesc, descNext->first);
89 close(mInotifyFileDesc);
93 g_source_remove(mInotifySource);
102 PRUint32 watchFlags =
103 IN_MODIFY | IN_CREATE | IN_DELETE | IN_DELETE_SELF |
104 IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO;
106 LOG(
"%s: adding inotify hook for [%s]",
108 NS_ConvertUTF16toUTF8(aDirPath).
get());
110 int pathFileDesc = inotify_add_watch(mInotifyFileDesc,
111 NS_ConvertUTF16toUTF8(aDirPath).
get(),
113 if (pathFileDesc == -1) {
117 char *errorDesc = strerror_r(errnum, buf,
sizeof(buf));
118 LOG(
"%s: could not add inotify watch path [%s], error %d (%s)",
119 NS_ConvertUTF16toUTF8(aDirPath).
get(),
123 NS_WARNING(
"Could not add a inotify watch path!!");
129 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
130 "Could not notify listener of INVALID_DIRECTORY!");
132 return NS_ERROR_UNEXPECTED;
136 nsString(aDirPath)));
149 NS_ENSURE_SUCCESS(rv, rv);
151 return sbBaseFileSystemWatcher::StopWatching(aShouldSaveSession);
162 char buffer[
sizeof(
struct inotify_event) + PATH_MAX];
164 PRInt32 n = read(mInotifyFileDesc, buffer,
sizeof(buffer));
171 struct inotify_event *
event = (
struct inotify_event *) &buffer[i];
175 if (curEventFileDesc != mFileDescMap.end()) {
176 TRACE(
"%s: inotify event for %s length %u",
178 NS_ConvertUTF16toUTF8(curEventFileDesc->second).get(),
183 mTree->Update(curEventFileDesc->second);
191 if (
event->mask & IN_DELETE_SELF ||
event->mask & IN_MOVE_SELF) {
192 mFileDescMap.erase(curEventFileDesc->first);
193 inotify_rm_watch(mInotifyFileDesc, curEventFileDesc->first);
197 NS_ASSERTION(PR_FALSE,
198 "Error: Could not find a file desc for inotify event!");
202 i +=
sizeof(
struct inotify_event) + event->len;
223 nsCOMPtr<nsILocalFile> curPathFile =
224 do_CreateInstance(
"@mozilla.org/file/local;1", &rv);
225 NS_ENSURE_SUCCESS(rv, rv);
227 rv = curPathFile->InitWithPath(aChangePath);
228 NS_ENSURE_SUCCESS(rv, rv);
231 rv = curPathFile->Exists(&exists);
232 NS_ENSURE_SUCCESS(rv, rv);
236 rv = curPathFile->IsDirectory(&isDir);
238 NS_ENSURE_SUCCESS(rv, rv);
242 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not add a inotify hook!");
254 TRACE(
"%s: adding root path [%s] and friends (previously watching [%s])",
256 NS_ConvertUTF16toUTF8(aTreeRootPath).
get(),
265 mInotifyFileDesc = inotify_init();
266 NS_ENSURE_TRUE(mInotifyFileDesc != -1, NS_ERROR_UNEXPECTED);
270 GIOChannel *ioc = g_io_channel_unix_new(mInotifyFileDesc);
271 mInotifySource = g_io_add_watch_full(ioc,
277 g_io_channel_unref(ioc);
284 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
285 "Could not add inotify hook for the root watch path!");
288 PRUint32 pathCount = aDirPathArray.Length();
289 for (PRUint32
i = 0;
i < pathCount;
i++) {
291 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
292 "Could not add inotify hook for a directory path!");
298 NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr< sbIFileSystemListener > mListener
sbLinuxFileSystemWatcher()
nsresult AddInotifyHook(const nsAString &aDirPath)
#define SB_PRLOG_SETUP(x)
nsTArray< nsString > sbStringArray
NS_DECL_ISUPPORTS NS_DECL_SBIFILESYSTEMWATCHER NS_IMETHOD OnChangeFound(const nsAString &aChangePath, EChangeType aChangeType)
sbFileDescMap::const_iterator sbFileDescIter
NS_IMETHOD OnTreeReady(const nsAString &aTreeRootPath, sbStringArray &aDirPathArray)
const unsigned long INVALID_DIRECTORY
nsRefPtr< sbFileSystemTree > mTree
nsresult OnInotifyEvent()
NS_IMETHOD OnChangeFound(const nsAString &aChangePath, EChangeType aChangeType)
sbFileDescMap::value_type sbFileDescPair
virtual ~sbLinuxFileSystemWatcher()
static gboolean Inotify_Callback(GIOChannel *source, GIOCondition condition, gpointer data)
NS_IMETHOD StopWatching(PRBool aShouldSaveSession)
_getSelectedPageStyle s i
#define SB_UNUSED_IN_RELEASE(decl)