Fix #2140 template file attributes applied.

Not yet sure if stat is a standard way to check file attributes. 
Some Unix use different command I think.