Skip to content

Commit

Permalink
Fix SPACK-93, SPACK-94, GitHub #150
Browse files Browse the repository at this point in the history
- `remove_prefix` was modified to remove from the DB, but the package
  may not have been added to the DB yet when `remove_prefix` is called
  from `cleanup`.

- Made `remove_prefix` a pure utility function (it just removes the prefix)

- Added `installed_db.remove()` call only after the `remove_prefix` in
  `uninstall`.
  • Loading branch information
tgamblin committed Nov 5, 2015
1 parent 339da1d commit 0d99394
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from external import argparse
import spack

description = "Correct database irregularities"
description = "Rebuild Spack's package database."

# Very basic version of spack fsck
def fsck(parser, args):
def reindex(parser, args):
spack.installed_db.reindex(spack.install_layout)
19 changes: 5 additions & 14 deletions lib/spack/spack/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class InstallRecord(object):
"""
def __init__(self, spec, path, installed, ref_count=0):
self.spec = spec
self.path = path
self.installed = installed
self.path = str(path)
self.installed = bool(installed)
self.ref_count = ref_count

def to_dict(self):
Expand Down Expand Up @@ -173,7 +173,7 @@ def _write_to_yaml(self, stream):
# map from per-spec hash code to installation record.
installs = dict((k, v.to_dict()) for k, v in self._data.items())

# databaes includes installation list and version.
# database includes installation list and version.

# NOTE: this DB version does not handle multiple installs of
# the same spec well. If there are 2 identical specs with
Expand Down Expand Up @@ -336,15 +336,14 @@ def _write(self):
Does no locking.
"""
temp_name = '%s.%s.temp' % (socket.getfqdn(), os.getpid())
temp_file = join_path(self._db_dir, temp_name)
temp_file = self._index_path + (
'.%s.%s.temp' % (socket.getfqdn(), os.getpid()))

# Write a temporary database file them move it into place
try:
with open(temp_file, 'w') as f:
self._write_to_yaml(f)
os.rename(temp_file, self._index_path)

except:
# Clean up temp file if something goes wrong.
if os.path.exists(temp_file):
Expand All @@ -367,14 +366,6 @@ def _read(self):
self.reindex(spack.install_layout)


def read(self):
with self.read_transaction(): pass


def write(self):
with self.write_transaction(): pass


def _add(self, spec, path, directory_layout=None):
"""Add an install record for spec at path to the database.
Expand Down
4 changes: 2 additions & 2 deletions lib/spack/spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ def url_version(self, version):
def remove_prefix(self):
"""Removes the prefix for a package along with any empty parent directories."""
spack.install_layout.remove_install_directory(self.spec)
spack.installed_db.remove(self.spec)


def do_fetch(self):
Expand Down Expand Up @@ -877,7 +876,7 @@ def build_log_path(self):
if self.installed:
return spack.install_layout.build_log_path(self.spec)
else:
return join_path(self.stage.source_path, 'spack-build.out')
return join_path(self.stage.source_path, 'spack-build.out')


@property
Expand Down Expand Up @@ -934,6 +933,7 @@ def do_uninstall(self, force=False):

# Uninstalling in Spack only requires removing the prefix.
self.remove_prefix()
spack.installed_db.remove(self.spec)
tty.msg("Successfully uninstalled %s." % self.spec.short_spec)

# Once everything else is done, run post install hooks
Expand Down
11 changes: 9 additions & 2 deletions lib/spack/spack/test/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ def tearDown(self):
spack.installed_db = self.spack_installed_db


def test_005_db_exists(self):
"""Make sure db cache file exists after creating."""
index_file = join_path(self.install_path, '.spack-db', 'index.yaml')
lock_file = join_path(self.install_path, '.spack-db', 'lock')

self.assertTrue(os.path.exists(index_file))
self.assertTrue(os.path.exists(lock_file))


def test_010_all_install_sanity(self):
"""Ensure that the install layout reflects what we think it does."""
all_specs = spack.install_layout.all_specs()
Expand Down Expand Up @@ -182,8 +191,6 @@ def test_015_write_and_read(self):
with spack.installed_db.write_transaction():
specs = spack.installed_db.query()
recs = [spack.installed_db.get_record(s) for s in specs]
spack.installed_db.write()
spack.installed_db.read()

for spec, rec in zip(specs, recs):
new_rec = spack.installed_db.get_record(spec)
Expand Down

0 comments on commit 0d99394

Please sign in to comment.