Only call chmod if the file is not a symlink. Older versions of chmod (shipped with ubuntu) don't support the -h flag.