summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@lucas-nussbaum.net>2009-06-18 09:30:25 +0200
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2009-06-18 09:30:25 +0200
commit87dc108bc909042a9f493754d767a368f293c003 (patch)
tree358aa4c3e656c7810b733036ddb4edd7bd23380a /lib
parent6acc50198e3303e7793aa95d3ec14e93b1579902 (diff)
downloadfeed2imap-87dc108bc909042a9f493754d767a368f293c003.tar.gz
feed2imap-87dc108bc909042a9f493754d767a368f293c003.tar.bz2
feed2imap-87dc108bc909042a9f493754d767a368f293c003.zip
Fix buffering problem with filters
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/feed2imap.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb
index d892eda..68051c7 100644
--- a/lib/feed2imap/feed2imap.rb
+++ b/lib/feed2imap/feed2imap.rb
@@ -135,16 +135,24 @@ class Feed2Imap
else
@logger.warn("No way to fetch feed #{feed.name} !")
end
- if feed.filter
+ if feed.filter and s != nil
# avoid running more than one command at the same time.
# We need it because the called command might not be
# thread-safe, and we need to get the right exitcode.
mutex.lock
- Open3::popen3(feed.filter) do |stdin, stdout|
+ # hack hack hack, avoid buffering problems
+ stdin, stdout, stderr = Open3::popen3(feed.filter)
+ inth = Thread::new do
stdin.puts s
stdin.close
- s = stdout.read
end
+ output = nil
+ outh = Thread::new do
+ output = stdout.read
+ end
+ inth.join
+ outh.join
+ s = output
if $?.exitstatus != 0
@logger.warn("Filter command for #{feed.name} exited with status #{$?.exitstatus}. Output might be corrupted !")
end