<commit_before>#!/bin/bash
# Copyright 2012-2014 by <NAME> <EMAIL>
# Distributed under the Eclipse Public License 1.0
# wait (using lsof) to see whether the file passed to lowriter is being used
# lsof is a CPU hog under Linux, inotify would be several magnitudes faster
# but needs the (optional) inotify-tools
# inotifywait -e modify /var/log/messages
# On MacOSX lsof is less a CPU hog
# fuser is an alternative, too. Faster on Linux

$* &

# our logfile
logFile="$HOME/elexis/logs/opendocument.log"
mkdir -p `dirname $logFile`

# log message our log file
function log2file {
  msg="`date +"%Y:%m:%d %H:%M:%S"` $1"
  echo $msg 
  echo $msg >> $logFile
}

# Find out which parameter is the file to watch
for j in $*
do
  if [ -f $j ] && [ ! -x $j ]
  then
    watchFile=$j
    break
  fi
done


# wait max 30 seconds for the watchFile to be opened
maxWait=100
nrWaits=0
log2file "Waiting for $watchFile"
while [ 1 ]
do
  sleep 0.3
  nrWaits=$[ $nrWaits + 1 ]
  timeout 1 fuser --silent $watchFile 
  res=$?
  if [ "$nrWaits" -gt "$maxWait" ] || [ $res -eq 0 ] ; then break ; fi
done
log2file "After $nrWaits sleeps $watchFile is open"

# wait for the lockfile to disappear
while true
do
  timeout 1 fuser --silent $watchFile
  if [ $? -gt 0 ] ; then break ; fi
  sleep 1
done
log2file "$watchFile went away"

exit 0
# should we use --norestore and/or -o<commit_msg>[2895]open_odf.sh tests twice before declaring a document as closed<commit_after>#!/bin/bash
# Copyright 2012-2014 by <NAME> <EMAIL>
# Distributed under the Eclipse Public License 1.0
# wait (using lsof) to see whether the file passed to lowriter is being used
# lsof is a CPU hog under Linux, inotify would be several magnitudes faster
# but needs the (optional) inotify-tools
# inotifywait -e modify /var/log/messages
# On MacOSX lsof is less a CPU hog
# fuser is an alternative, too. Faster on Linux

$* &

# our logfile
logFile="$HOME/elexis/logs/opendocument.log"
mkdir -p `dirname $logFile`

# log message our log file
function log2file {
  msg="`date +"%Y:%m:%d %H:%M:%S"` $1"
  echo $msg 
  echo $msg >> $logFile
}

# Find out which parameter is the file to watch
for j in $*
do
  if [ -f $j ] && [ ! -x $j ]
  then
    watchFile=$j
    break
  fi
done


# wait max 30 seconds for the watchFile to be opened
maxWait=100
nrWaits=0
log2file "Waiting for $watchFile"
while [ 1 ]
do
  sleep 0.3
  nrWaits=$[ $nrWaits + 1 ]
  # cannot use --silent on MacOSX
  timeout 1 fuser  $watchFile
  res=$?
  if [ "$nrWaits" -gt "$maxWait" ] || [ $res -eq 0 ] ; then break ; fi
done
log2file "After $nrWaits sleeps $watchFile is open"

# wait for the lockfile to disappear
function waitForFile2vanish() {
	while true
	do
	  # don't use --silent. Not supported on MacOSX
	  timeout 1 fuser $watchFile
	  if [ $? -gt 0 ] ; then break ; fi
	  sleep 1
	done
	log2file "$watchFile went away"
}

while true
do
	waitForFile2vanish
	sleep 1 # and a second time to be sure
	waitForFile2vanish
	timeout 1 fuser --silent $watchFile
	if [ $? -gt 0 ] ; then break ; fi
done

exit 0
# should we use --norestore and/or -o
{'fraction_non_alphanumeric': 0.10697977821265492, 'fraction_numerical': 0.023483365949119372, 'mean_word_length': 3.3814285714285712, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6638885', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1092, 'n_words': 434}