Repository: spack/spack

Issue:
Installation issue: iozone Permission denied: 'makefile'
### Steps to reproduce the issue


```console
$ spack install iozone %gcc@4.8.5 target=x86_64
[spack-build-env.txt](https://github.com/spack/spack/files/4793435/spack-build-env.txt)

==> 2011: Installing iozone
==> Finding buildcaches at http://spack.pi.sjtu.edu.cn/mirror/build_cache
==> Finding buildcaches in /lustre/home/rpm/pkgs/build_cache
==> Fetching file:///lustre/home/rpm/pkgs/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr.spec.yaml
curl: (37) Couldn't open file /lustre/home/rpm/pkgs/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr.sp
ec.yaml
==> Failed to fetch file from URL: file:///lustre/home/rpm/pkgs/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgj
ta4k3xpfr.spec.yaml
    Curl failed with error 37
==> Fetching from file:///lustre/home/rpm/pkgs/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr.spec.ya
ml failed.
==> Fetching http://spack.pi.sjtu.edu.cn/mirror/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr.spec.y
aml

curl: (22) The requested URL returned error: 404 Not Found
==> Failed to fetch file from URL: http://spack.pi.sjtu.edu.cn/mirror/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpf
ungrgjta4k3xpfr.spec.yaml
    URL http://spack.pi.sjtu.edu.cn/mirror/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr.spec.yaml w
as not found!
==> Fetching from http://spack.pi.sjtu.edu.cn/mirror/build_cache/linux-centos7-x86_64-gcc-4.8.5-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr.s
pec.yaml failed.
==> Using cached archive: /lustre/home/rpm/.spack/sourcecache/_source-cache/archive/2e/2e3d72916e7d7340a7c505fc0c3d28553fcc5ff2daf41d811368e55b
d4e6a293.tar
==> Staging archive: /tmp/rpm/spack-stage-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr/iozone3_465.tar
==> Created stage in /tmp/rpm/spack-stage-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr
==> No patches needed for iozone
==> 2011: iozone: Building iozone [MakefilePackage]
==> 2011: iozone: Executing phase: 'edit'
==> Error: PermissionError: [Errno 13] Permission denied: 'makefile'

/lustre/opt/spack/var/spack/repos/builtin/packages/iozone/package.py:28, in edit:
         25        with working_dir(self.build_directory):
         26            filter_file(r'^CC\t= cc',
         27                        r'CC\t= {0}'.format(spack_cc),
  >>     28                        'makefile')

See build log for details:
  /tmp/rpm/spack-stage-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr/spack-build-out.txt

==> Error: Failed to install iozone due to ChildError: PermissionError: [Errno 13] Permission denied: 'makefile'
/lustre/opt/spack/var/spack/repos/builtin/packages/iozone/package.py:28, in edit:
         25        with working_dir(self.build_directory):
         26            filter_file(r'^CC\t= cc',
         27                        r'CC\t= {0}'.format(spack_cc),
  >>     28                        'makefile')

See build log for details:
  /tmp/rpm/spack-stage-iozone-3_465-g2zmi6fidf4fifnpfungrgjta4k3xpfr/spack-build-out.txt
Traceback (most recent call last):
  File "/lustre/opt/spack/lib/spack/spack/build_environment.py", line 819, in child_process
    return_value = function()
  File "/lustre/opt/spack/lib/spack/spack/installer.py", line 1130, in build_process
    phase(pkg.spec, pkg.prefix)
  File "/lustre/opt/spack/lib/spack/spack/package.py", line 108, in phase_wrapper
    phase(spec, prefix)
  File "/lustre/opt/spack/var/spack/repos/builtin/packages/iozone/package.py", line 29, in edit
  File "/lustre/opt/spack/lib/spack/llnl/util/filesystem.py", line 180, in filter_file
    with open(filename, mode='w', **extra_kwargs) as output_file:
PermissionError: [Errno 13] Permission denied: 'makefile'
```

### Information on your system

<!-- Please include the output of `spack debug report` -->
```
* **Spack:** 0.14.2-1444-4b48f70
* **Python:** 3.6.8
* **Platform:** linux-centos7-skylake_avx512
```

### Additional information

* [spack-build-out.txt](https://github.com/spack/spack/files/4793441/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/4793444/spack-build-env.txt)
### General information

- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [x] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:
Just ran into the same issue attempting to install iozone,
`==> iozone: Executing phase: 'edit'
==> Error: PermissionError: [Errno 13] Permission denied: 'makefile'`


Any resolution on this yet? Thanks!

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/iozone/package.py b/var/spack/repos/builtin/packages/iozone/package.py
--- a/var/spack/repos/builtin/packages/iozone/package.py
+++ b/var/spack/repos/builtin/packages/iozone/package.py
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
 from spack import *
+import os
 
 
 class Iozone(MakefilePackage):
@@ -14,6 +15,7 @@ class Iozone(MakefilePackage):
     homepage = "http://www.iozone.org/"
     url      = "http://www.iozone.org/src/current/iozone3_465.tar"
 
+    version('3_491', sha256='2cc4842d382e46a585d1df9ae1e255695480dcc0fc05c3b1cb32ef3493d0ec9a')
     version('3_465', sha256='2e3d72916e7d7340a7c505fc0c3d28553fcc5ff2daf41d811368e55bd4e6a293')
 
     # TODO: Add support for other architectures as necessary
@@ -22,6 +24,11 @@ class Iozone(MakefilePackage):
     build_directory = 'src/current'
 
     def edit(self, spec, prefix):
+        for dirpath, dirnames, filenames in os.walk(self.stage.source_path):
+            for filename in filenames:
+                path = os.path.join(dirpath, filename)
+                os.chmod(path, 0o644)
+
         with working_dir(self.build_directory):
             filter_file(r'^CC\t= cc',
                         r'CC\t= {0}'.format(spack_cc),


Test patch: