# Buggy code
def is_activated(self, view):
    """Return True if package is activated."""
    if not self.is_extension:
        raise ValueError("is_activated called on package that is not an extension.")
    extensions_layout = view.extensions_layout
    exts = extensions_layout.extension_map(self.extendee_spec)
    return (self.name in exts) and (exts[self.name] == self.spec)


# Traceback (PermissionError)
==> [2020-04-09-10:26:40.615561, 133285] WRITE LOCK (scons): /dcsrsoft/sandbox/eroche/meleze/opt/spack/.spack-db/prefix_lock[2450758027729552401:1] [Releasing]
==> [2020-04-09-10:26:40.615767, 133285] WRITE LOCK (scons): /dcsrsoft/sandbox/eroche/meleze/opt/spack/.spack-db/prefix_lock[2450758027729552401:1] [Released at 10:26:40.615744]
Traceback (most recent call last):
File "/dcsrsoft/sandbox/eroche/meleze/bin/spack", line 64, in <module>
sys.exit(spack.main.main())
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/main.py", line 763, in main
return _invoke_command(command, parser, args, unknown)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/main.py", line 488, in _invoke_command
return_val = command(parser, args)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/cmd/uninstall.py", line 348, in uninstall
uninstall_specs(args, specs)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/cmd/uninstall.py", line 323, in uninstall_specs
do_uninstall(env, uninstall_list, args.force)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/cmd/uninstall.py", line 225, in do_uninstall
item.do_uninstall(force=force)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/package.py", line 1739, in do_uninstall
Package.uninstall_by_spec(self.spec, force)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/package.py", line 1711, in uninstall_by_spec
spack.hooks.pre_uninstall(spec)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/hooks/__init__.py", line 59, in __call__
hook(*args, **kwargs)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/hooks/extensions.py", line 18, in pre_uninstall
if pkg.is_activated(view):
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/package.py", line 1008, in is_activated
exts = extensions_layout.extension_map(self.extendee_spec)
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/directory_layout.py", line 430, in extension_map
return self._extension_map(spec).copy()
File "/dcsrsoft/sandbox/eroche/meleze/lib/spack/spack/directory_layout.py", line 457, in _extension_map
with open(path) as ext_file:
PermissionError: [Errno 13] Permission denied: '/dcsrsoft/spack/meleze/v2/opt/spack/linux-centos7-skylake_avx512/gcc-8.3.0/python-3.7.6-3qfa6rjryjmwkj7zdc26ntxkqxq6mkdi/.spack/extensions.yaml'

# Fixed code
def is_activated(self, view):
    """Return True if package is activated."""
    if not self.is_extension:
        raise ValueError("is_activated called on package that is not an extension.")
    if self.extendee_spec.package.installed_upstream:
        # If this extends an upstream package, it cannot be activated for
        # it. This bypasses construction of the extension map, which can
        # can fail when run in the context of a downstream Spack instance
        return False
    extensions_layout = view.extensions_layout
    exts = extensions_layout.extension_map(self.extendee_spec)
    return (self.name in exts) and (exts[self.name] == self.spec)