Refactor: move setting of file handles into a function

Change-Id: Iec4cd00d0a728267a6d1361304cd0a5de4857c91
Reviewed-on: http://review.couchbase.org/33128
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>