Add helper function to get a filesize
(cherry picked from commit 07db83fd086363c778b921d15118b97bf81da646)
Don't try to import empty file

See bug #9578.
(cherry picked from commit a1fe583a1f43473b07befb7c56fd38b92df6b34e)