mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
Remove FileMonitorBlocker which does not work reliably on all platforms
This commit is contained in:
parent
b30161b591
commit
fd6189b7e3
@ -382,9 +382,6 @@ public:
|
|||||||
/// Notify or clear of external modification
|
/// Notify or clear of external modification
|
||||||
void fileExternallyModified(bool exists) const;
|
void fileExternallyModified(bool exists) const;
|
||||||
|
|
||||||
/// Block notifications of external modifications
|
|
||||||
FileMonitorBlocker blockFileMonitor() { return file_monitor_->block(); }
|
|
||||||
|
|
||||||
/// has been externally modified? Can be reset by the user.
|
/// has been externally modified? Can be reset by the user.
|
||||||
mutable bool externally_modified_;
|
mutable bool externally_modified_;
|
||||||
|
|
||||||
@ -1379,7 +1376,6 @@ FileName Buffer::getBackupName() const {
|
|||||||
// Should probably be moved to somewhere else: BufferView? GuiView?
|
// Should probably be moved to somewhere else: BufferView? GuiView?
|
||||||
bool Buffer::save() const
|
bool Buffer::save() const
|
||||||
{
|
{
|
||||||
FileMonitorBlocker block = d->blockFileMonitor();
|
|
||||||
docstring const file = makeDisplayPath(absFileName(), 20);
|
docstring const file = makeDisplayPath(absFileName(), 20);
|
||||||
d->filename.refresh();
|
d->filename.refresh();
|
||||||
|
|
||||||
@ -5338,8 +5334,7 @@ void Buffer::Impl::refreshFileMonitor()
|
|||||||
|
|
||||||
void Buffer::Impl::fileExternallyModified(bool const exists) const
|
void Buffer::Impl::fileExternallyModified(bool const exists) const
|
||||||
{
|
{
|
||||||
// prevent false positives, because FileMonitorBlocker is not enough on
|
// ignore notifications after our own saving operations
|
||||||
// OSX.
|
|
||||||
if (checksum_ == filename.checksum()) {
|
if (checksum_ == filename.checksum()) {
|
||||||
LYXERR(Debug::FILES, "External modification but "
|
LYXERR(Debug::FILES, "External modification but "
|
||||||
"checksum unchanged: " << filename);
|
"checksum unchanged: " << filename);
|
||||||
|
@ -202,42 +202,6 @@ void FileMonitor::changed(bool const exists)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileMonitorBlocker FileMonitor::block(int delay)
|
|
||||||
{
|
|
||||||
FileMonitorBlocker blocker = blocker_.lock();
|
|
||||||
if (!blocker)
|
|
||||||
blocker_ = blocker = make_shared<FileMonitorBlockerGuard>(this);
|
|
||||||
blocker->setDelay(delay);
|
|
||||||
return blocker;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FileMonitorBlockerGuard::FileMonitorBlockerGuard(FileMonitor * monitor)
|
|
||||||
: monitor_(monitor), delay_(0)
|
|
||||||
{
|
|
||||||
QObject::disconnect(monitor->monitor_.get(), SIGNAL(fileChanged(bool)),
|
|
||||||
monitor, SLOT(changed(bool)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FileMonitorBlockerGuard::setDelay(int delay)
|
|
||||||
{
|
|
||||||
delay_ = max(delay_, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FileMonitorBlockerGuard::~FileMonitorBlockerGuard()
|
|
||||||
{
|
|
||||||
if (!monitor_)
|
|
||||||
return;
|
|
||||||
// Even if delay_ is 0, the QTimer is necessary. Indeed, the notifications
|
|
||||||
// from QFileSystemWatcher that we meant to ignore are not going to be
|
|
||||||
// treated immediately, so we must yield to give us the opportunity to
|
|
||||||
// ignore them.
|
|
||||||
QTimer::singleShot(delay_, monitor_, SLOT(connectToFileMonitorGuard()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ActiveFileMonitor::ActiveFileMonitor(std::shared_ptr<FileMonitorGuard> monitor,
|
ActiveFileMonitor::ActiveFileMonitor(std::shared_ptr<FileMonitorGuard> monitor,
|
||||||
FileName const & filename, int interval)
|
FileName const & filename, int interval)
|
||||||
: FileMonitor(monitor), filename_(filename), interval_(interval),
|
: FileMonitor(monitor), filename_(filename), interval_(interval),
|
||||||
|
@ -60,12 +60,6 @@ typedef std::unique_ptr<ActiveFileMonitor> ActiveFileMonitorPtr;
|
|||||||
/// monitor.connect(...);
|
/// monitor.connect(...);
|
||||||
/// (stops watching the first)
|
/// (stops watching the first)
|
||||||
///
|
///
|
||||||
/// Block notifications for the duration of a scope:
|
|
||||||
/// {
|
|
||||||
/// FileMonitorBlocker block = monitor.block();
|
|
||||||
/// ...
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// Reset connections:
|
/// Reset connections:
|
||||||
/// monitor.disconnect();
|
/// monitor.disconnect();
|
||||||
/// or the disconnect method of the connection object for the boost signal.
|
/// or the disconnect method of the connection object for the boost signal.
|
||||||
@ -131,27 +125,10 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class FileMonitorBlockerGuard : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
QPointer<FileMonitor> monitor_;
|
|
||||||
int delay_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
FileMonitorBlockerGuard(FileMonitor * monitor);
|
|
||||||
~FileMonitorBlockerGuard();
|
|
||||||
void setDelay(int delay);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef std::shared_ptr<FileMonitorBlockerGuard> FileMonitorBlocker;
|
|
||||||
|
|
||||||
|
|
||||||
/// Main class
|
/// Main class
|
||||||
class FileMonitor : public QObject
|
class FileMonitor : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class FileMonitorBlockerGuard;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileMonitor(std::shared_ptr<FileMonitorGuard> monitor);
|
FileMonitor(std::shared_ptr<FileMonitorGuard> monitor);
|
||||||
@ -165,20 +142,6 @@ public:
|
|||||||
void disconnect();
|
void disconnect();
|
||||||
/// absolute path being tracked
|
/// absolute path being tracked
|
||||||
std::string const & filename() { return monitor_->filename(); }
|
std::string const & filename() { return monitor_->filename(); }
|
||||||
/// Creates a guard that blocks notifications. Copyable. Notifications from
|
|
||||||
/// this monitor are blocked as long as there are copies of the
|
|
||||||
/// FileMonitorBlocker around.
|
|
||||||
/// \param delay is the amount waited in ms after expiration of the guard
|
|
||||||
/// before reconnecting. It can be used to slow down incoming events
|
|
||||||
/// accordingly. A value of 0 is still made asynchronous, because of the
|
|
||||||
/// fundamentally asynchronous nature of QFileSystemWatcher. To catch one's
|
|
||||||
/// own file operations, a value of 0 for delay is sufficient with the
|
|
||||||
/// inotify backend (e.g. Linux); for OSX (kqueue), a value of 100ms is
|
|
||||||
/// unsufficient and more tests need to be done in combination with
|
|
||||||
/// flushing/syncing to disk in order to understand how to catch one's own
|
|
||||||
/// operations reliably. No feedback about Windows. See
|
|
||||||
/// <https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg200252.html>.
|
|
||||||
FileMonitorBlocker block(int delay = 0);
|
|
||||||
/// Make sure the good file is being monitored, after e.g. a move or a
|
/// Make sure the good file is being monitored, after e.g. a move or a
|
||||||
/// deletion. See <https://bugreports.qt.io/browse/QTBUG-46483>. This is
|
/// deletion. See <https://bugreports.qt.io/browse/QTBUG-46483>. This is
|
||||||
/// called automatically.
|
/// called automatically.
|
||||||
@ -199,8 +162,6 @@ private:
|
|||||||
sig fileChanged_;
|
sig fileChanged_;
|
||||||
/// the unique watch for our file
|
/// the unique watch for our file
|
||||||
std::shared_ptr<FileMonitorGuard> const monitor_;
|
std::shared_ptr<FileMonitorGuard> const monitor_;
|
||||||
///
|
|
||||||
std::weak_ptr<FileMonitorBlockerGuard> blocker_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user