Added spack fsck and re-read from glob if the database file does not exist. Allows older versions to smoothly upgrade to the database.
This commit is contained in:
parent
9c8e46dc22
commit
cd23d2eaa2
43
lib/spack/spack/cmd/fsck.py
Normal file
43
lib/spack/spack/cmd/fsck.py
Normal file
@ -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()
|
@ -123,8 +123,15 @@ def read_database(self):
|
||||
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 @@ def write(self):
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user