From 0d993947ee5a4c29451cf0ee40f47519e1c3c4d9 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 4 Nov 2015 16:44:33 -0800 Subject: Fix SPACK-93, SPACK-94, GitHub #150 - `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`. --- lib/spack/spack/cmd/fsck.py | 32 -------------------------------- lib/spack/spack/cmd/reindex.py | 31 +++++++++++++++++++++++++++++++ lib/spack/spack/database.py | 19 +++++-------------- lib/spack/spack/package.py | 4 ++-- lib/spack/spack/test/database.py | 11 +++++++++-- 5 files changed, 47 insertions(+), 50 deletions(-) delete mode 100644 lib/spack/spack/cmd/fsck.py create mode 100644 lib/spack/spack/cmd/reindex.py diff --git a/lib/spack/spack/cmd/fsck.py b/lib/spack/spack/cmd/fsck.py deleted file mode 100644 index 9a3c450dcf..0000000000 --- a/lib/spack/spack/cmd/fsck.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# Copyright (c) 2013-2015, Lawrence Livermore National Security, LLC. -# Produced at the Lawrence Livermore National Laboratory. -# -# This file is part of Spack. -# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. -# LLNL-CODE-647188 -# -# For details, see https://scalability-llnl.github.io/spack -# Please also see the LICENSE file for our notice and the LGPL. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License (as published by -# the Free Software Foundation) version 2.1 dated February 1999. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and -# conditions of the GNU General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -############################################################################## -from external import argparse -import spack - -description = "Correct database irregularities" - -# Very basic version of spack fsck -def fsck(parser, args): - spack.installed_db.reindex(spack.install_layout) diff --git a/lib/spack/spack/cmd/reindex.py b/lib/spack/spack/cmd/reindex.py new file mode 100644 index 0000000000..b584729ea4 --- /dev/null +++ b/lib/spack/spack/cmd/reindex.py @@ -0,0 +1,31 @@ +############################################################################## +# Copyright (c) 2013-2015, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://scalability-llnl.github.io/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License (as published by +# the Free Software Foundation) version 2.1 dated February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +from external import argparse +import spack + +description = "Rebuild Spack's package database." + +def reindex(parser, args): + spack.installed_db.reindex(spack.install_layout) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index 9ce00a45e9..e0c14a0455 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -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): @@ -173,7 +173,7 @@ class Database(object): # 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 @@ -336,15 +336,14 @@ class Database(object): 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): @@ -367,14 +366,6 @@ class Database(object): 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. diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index b15d4b2040..c631a35bf3 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -611,7 +611,6 @@ class Package(object): 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): @@ -877,7 +876,7 @@ class Package(object): 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 @@ -934,6 +933,7 @@ class Package(object): # 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 diff --git a/lib/spack/spack/test/database.py b/lib/spack/spack/test/database.py index 3c5926e840..8416143f2d 100644 --- a/lib/spack/spack/test/database.py +++ b/lib/spack/spack/test/database.py @@ -148,6 +148,15 @@ class DatabaseTest(MockPackagesTest): 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() @@ -182,8 +191,6 @@ class DatabaseTest(MockPackagesTest): 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) -- cgit v1.2.3-70-g09d2