summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGregory Becker <becker33@llnl.gov>2015-09-15 14:20:19 -0700
committerGregory Becker <becker33@llnl.gov>2015-09-15 14:20:19 -0700
commitcd23d2eaa2d06e4a407a4ae88c28d13cbbd7fd1e (patch)
treea7180c4a036dad829e5341fc6a1025c6cdc914c5 /lib
parent9c8e46dc228e096a83a892e5f53424bb3446d8f6 (diff)
downloadspack-cd23d2eaa2d06e4a407a4ae88c28d13cbbd7fd1e.tar.gz
spack-cd23d2eaa2d06e4a407a4ae88c28d13cbbd7fd1e.tar.bz2
spack-cd23d2eaa2d06e4a407a4ae88c28d13cbbd7fd1e.tar.xz
spack-cd23d2eaa2d06e4a407a4ae88c28d13cbbd7fd1e.zip
Added spack fsck and re-read from glob if the database file does not exist. Allows older versions to smoothly upgrade to the database.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/fsck.py43
-rw-r--r--lib/spack/spack/database.py18
2 files changed, 57 insertions, 4 deletions
diff --git a/lib/spack/spack/cmd/fsck.py b/lib/spack/spack/cmd/fsck.py
new file mode 100644
index 0000000000..3141a7031d
--- /dev/null
+++ b/lib/spack/spack/cmd/fsck.py
@@ -0,0 +1,43 @@
+##############################################################################
+# Copyright (c) 2013, 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
+
+from llnl.util.lock import *
+
+import spack
+import os
+
+description = "Correct database irregularities"
+
+#Very basic version of spack fsck
+def fsck(parser, args):
+ with Write_Lock_Instance(spack.installed_db.lock,1800):
+ #remove database file
+ if os.path.exists(spack.installed_db._file_path):
+ os.remove(spack.installed_db._file_path)
+ #read database
+ spack.installed_db.read_database()
+ #write database
+ spack.installed_db.write()
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index 9b759827d3..680d184f1f 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -123,8 +123,15 @@ class Database(object):
with open(self._file_path,'r') as f:
self._read_from_yaml(f)
else:
- #The file doesn't exist, construct empty data.
+ #The file doesn't exist, construct from file paths
self._data = []
+ specs = spack.install_layout.all_specs()
+ for spec in specs:
+ sph = {}
+ sph['spec']=spec
+ sph['hash']=spec.dag_hash()
+ sph['path']=spack.install_layout.path_for_spec(spec)
+ self._data.append(sph)
def _write_database_to_yaml(self,stream):
@@ -167,10 +174,13 @@ class Database(object):
def is_dirty(self):
"""
- Returns true iff the database file exists
- and was most recently written to by another spack instance.
+ Returns true iff the database file does not exist
+ or was most recently written to by another spack instance.
"""
- return (os.path.isfile(self._file_path) and (os.path.getmtime(self._file_path) > self._last_write_time))
+ if not os.path.isfile(self._file_path):
+ return True
+ else:
+ return (os.path.getmtime(self._file_path) > self._last_write_time)
# @_autospec