From 9760210c775bd6f35c31ea82370a2d1a4ce23dd2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= <josef.soentgen@genode-labs.com>
Date: Wed, 30 May 2018 17:54:13 +0200
Subject: [PATCH] fs_rom: revert notification changes

---
 repos/os/src/server/fs_rom/main.cc | 42 +++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/repos/os/src/server/fs_rom/main.cc b/repos/os/src/server/fs_rom/main.cc
index 2a42d5519a..d6f4b4bd25 100755
--- a/repos/os/src/server/fs_rom/main.cc
+++ b/repos/os/src/server/fs_rom/main.cc
@@ -257,18 +257,37 @@ class Fs_rom::Rom_session_component : public  Rpc_object<Rom_session>
 			catch (Permission_denied) { error(_file_path, ": permission denied"); }
 			catch (...)               { error(_file_path, ": unhandled error"); };
 
-			if (_file_size > 0) {
-				memset(_file_ds.local_addr<char>(), 0x00, min(_file_size, _file_ds.size()));
-				_file_size = 0;
-			}
-
 			return false;
 		}
 
 		void _notify_client_about_new_version()
 		{
-			if (_sigh.valid() && _curr_version.value != _handed_out_version.value)
-				Signal_transmitter(_sigh).submit();
+			using namespace File_system;
+
+			if (_sigh.valid() && _curr_version.value != _handed_out_version.value) {
+
+				/* notify if the file exists and is not empty */
+				try {
+					Node_handle file = _fs.node(_file_path.base());
+					Handle_guard g(_fs, file);
+					_file_size = _fs.status(file).size;
+					if (_file_size > 0) {
+						/* assume a transition between versions */
+						Signal_transmitter(_sigh).submit();
+					}
+				}
+
+				/* notify if the file is removed */
+				catch (File_system::Lookup_failed) {
+					if (_file_size > 0) {
+						memset(_file_ds.local_addr<char>(), 0x00, _file_size);
+						_file_size = 0;
+						Signal_transmitter(_sigh).submit();
+					}
+				}
+
+				catch (...) { }
+			}
 		}
 
 	public:
@@ -356,9 +375,11 @@ class Fs_rom::Rom_session_component : public  Rpc_object<Rom_session>
 					_open_watch_handle();
 				}
 
-				/* notify the client of the change */
-				_curr_version = Version { _curr_version.value + 1 };
-				_notify_client_about_new_version();
+				if (_watching_file) {
+					/* notify the client of the change */
+					_curr_version = Version { _curr_version.value + 1 };
+					_notify_client_about_new_version();
+				}
 				return;
 
 			case File_system::Packet_descriptor::READ: {
@@ -456,6 +477,7 @@ class Fs_rom::Rom_root : public Root_component<Fs_rom::Rom_session_component>
 			Root_component<Rom_session_component>(env.ep(), md_alloc),
 			_env(env)
 		{
+			/* Process CONTENT_CHANGED acknowledgement packets at the entrypoint  */
 			_fs.sigh_ack_avail(_packet_handler);
 
 			env.parent().announce(env.ep().manage(*this));