FileMonitor.cpp
branchv_0
changeset 23 42341f66de52
parent 7 e6065118326f
child 29 dc3c102e1264
equal deleted inserted replaced
22:12262f2420de 23:42341f66de52
    50 public:
    50 public:
    51 	int fd;
    51 	int fd;
    52 	std::map<int, std::string> fileNames;
    52 	std::map<int, std::string> fileNames;
    53 
    53 
    54 	void unwatch(int wd) {
    54 	void unwatch(int wd) {
       
    55 		fileNames.erase(wd);
    55 		int result = inotify_rm_watch(fd, wd);
    56 		int result = inotify_rm_watch(fd, wd);
    56 		checkError(result < 0, "unable to stop monitoring a file: ");
    57 		checkError(result < 0, "unable to stop monitoring a file: ");
    57 		fileNames.erase(wd);
       
    58 	}
    58 	}
    59 
    59 
    60 	virtual ~Impl() {
    60 	virtual ~Impl() {
    61 		close(fd);
    61 		close(fd);
    62 	}
    62 	}
   107 		return false;
   107 		return false;
   108 	}
   108 	}
   109 }
   109 }
   110 
   110 
   111 WatchedFile::Impl::~Impl() {
   111 WatchedFile::Impl::~Impl() {
   112 	fileMonitorImpl->unwatch(wd);
   112 	try {
       
   113 		fileMonitorImpl->unwatch(wd);
       
   114 	} catch (const std::exception& e) {
       
   115 		// ignored, fails after file deletion
       
   116 		// std::cerr << "unwatch failed: " << e.what() << std::endl;
       
   117 	}
   113 }
   118 }
   114 
   119 
   115 FileMonitor WatchedFile::getFileMonitor() const {
   120 FileMonitor WatchedFile::getFileMonitor() const {
   116 	return FileMonitor(impl->fileMonitorImpl);
   121 	return FileMonitor(impl->fileMonitorImpl);
   117 }
   122 }