From 4b85b4a5264a681cc69a793ed2fa1f950ec061e8 Mon Sep 17 00:00:00 2001 From: Alex Ameen Date: Wed, 19 Jul 2023 08:22:08 -0500 Subject: [PATCH] kill some dead code --- include/flox/flox-flake.hh | 15 +--- src/flox-flake.cc | 174 ------------------------------------- tests/drv-cache.cc | 13 --- tests/resolve.cc | 14 --- 4 files changed, 3 insertions(+), 213 deletions(-) diff --git a/include/flox/flox-flake.hh b/include/flox/flox-flake.hh index d992e5b..4e12f4f 100644 --- a/include/flox/flox-flake.hh +++ b/include/flox/flox-flake.hh @@ -107,7 +107,7 @@ class FloxFlake : public std::enable_shared_from_this { std::shared_ptr getLockedFlake(); nix::ref openEvalCache(); - FloxFlakeRef getFlakeRef() const { return this->_flakeRef; } + FloxFlakeRef getFlakeRef() const { return this->_flakeRef; } FloxFlakeRef getLockedFlakeRef() @@ -115,9 +115,8 @@ class FloxFlake : public std::enable_shared_from_this { return this->getLockedFlake()->flake.lockedRef; } - std::list getSystems() const; - std::list> getDefaultFlakeAttrPathPrefixes() const; - std::list> getFlakeAttrPathPrefixes() const; + std::list getSystems() const; + std::list> getFlakeAttrPathPrefixes() const; /** * Like `findAttrAlongPath' but without suggestions. @@ -133,14 +132,6 @@ class FloxFlake : public std::enable_shared_from_this { /** Opens `EvalCache' once, staying open until all cursors die. */ std::list getFlakePrefixCursors(); - std::list> getActualFlakeAttrPathPrefixes(); - - /** - * Try opening cursors from an absolute or relative path with globs. - * Glob is only accepted for `system'. - */ - std::list openCursorsByAttrPathGlob( const AttrPathGlob & path ); - /** * Determine which output prefixes exist in this flake, ignoring * `preferences' and mark them in the `DrvDb'. diff --git a/src/flox-flake.cc b/src/flox-flake.cc index 5ea4f3c..0f27ee8 100644 --- a/src/flox-flake.cc +++ b/src/flox-flake.cc @@ -83,35 +83,6 @@ FloxFlake::getSystems() const } -/* -------------------------------------------------------------------------- */ - - std::list> -FloxFlake::getDefaultFlakeAttrPathPrefixes() const -{ - std::string system = nix::settings.thisSystem.get(); - if ( ! hasElement( this->_systems, system ) ) - { - return {}; - } - std::list> rsl; - for ( auto & prefix : this->_prefsPrefixes ) - { - if ( prefix == "catalog" ) - { - for ( auto & stability : this->_prefsStabilities ) - { - rsl.push_back( { "catalog", system, stability } ); - } - } - else - { - rsl.push_back( { prefix, system } ); - } - } - return rsl; -} - - /* -------------------------------------------------------------------------- */ std::list> @@ -259,98 +230,6 @@ FloxFlake::getFlakePrefixCursors() } -/* -------------------------------------------------------------------------- */ - - std::list> -FloxFlake::getActualFlakeAttrPathPrefixes() -{ - this->recordPrefixes(); - DrvDb db( this->getLockedFlake()->getFingerprint() ); - std::list> rsl; - - for ( std::list & prefix : this->getFlakeAttrPathPrefixes() ) - { - std::string subtree = std::move( prefix.front() ); - prefix.pop_front(); - std::string system = std::move( prefix.front() ); - prefix.pop_front(); - progress_status status = db.getProgress( subtree, system ); - switch ( status ) - { - case DBPS_EMPTY: continue; break; - case DBPS_MISSING: continue; break; - case DBPS_NONE: - throw ResolverException( - "FloxFlake::getActualFlakeAttrPathPrefixes(): Failed to read " - "progress from DrvDb." - ); - break; - case DBPS_INFO_DONE: - case DBPS_PATHS_DONE: - /* Handle stabilities */ - if ( prefix.empty() ) - { - std::vector path = { - std::move( subtree ), std::move( system ) - }; - rsl.push_back( std::move( path ) ); - } - else - { - std::string stability = std::move( prefix.front() ); - prefix.pop_front(); - auto state = db.getDbState(); - nix::SQLiteStmt stmt; - stmt.create( state->db - , "SELECT COUNT( subtree ) FROM Derivations WHERE " - "( subtree = ? ) AND ( system = ? ) AND ( path LIKE ? )" - ); - std::string like( "[\"" + stability + "\",%" ); - nix::SQLiteStmt::Use query = - stmt.use()( subtree )( system )( like ); - assert( query.next() ); - if ( query.getInt( 0 ) != 0 ) - { - std::vector path = { - std::move( subtree ) - , std::move( system ) - , std::move( stability ) - }; - rsl.push_back( std::move( path ) ); - } - } - break; - - default: - /* Handle stabilities */ - if ( prefix.empty() ) - { - std::vector path = { - std::move( subtree ), std::move( system ) - }; - rsl.push_back( std::move( path ) ); - } - else - { - std::vector path = { - std::move( subtree ) - , std::move( system ) - , std::move( prefix.front() ) - }; - prefix.pop_front(); - if ( this->maybeOpenCursor( path ) != nullptr ) - { - rsl.push_back( std::move( path ) ); - } - } - break; - } - } - - return rsl; -} - - /* -------------------------------------------------------------------------- */ void @@ -643,59 +522,6 @@ FloxFlake::packagesDo( } -/* -------------------------------------------------------------------------- */ - -// TODO: Use DrvDb - std::list -FloxFlake::openCursorsByAttrPathGlob( const AttrPathGlob & path ) -{ - - std::list rsl; - - if ( path.isAbsolute() ) - { - MaybeCursor prefix = this->openEvalCache()->getRoot()->maybeGetAttr( - std::get( path.path[0] ) - ); - if ( prefix == nullptr ) { return {}; } - if ( ! path.hasGlob() ) - { - MaybeCursor c = prefix; - for ( size_t i = 1; ( i < path.size() ) && ( c != nullptr ); ++i ) - { - c = c->maybeGetAttr( std::get( path.path[i] ) ); - } - if ( c != nullptr ) { rsl.push_back( std::move( (Cursor) c ) ); } - } - else - { - for ( const auto & system : this->_systems ) - { - MaybeCursor c = prefix->maybeGetAttr( system ); - for ( size_t i = 2; ( i < path.size() ) && ( c != nullptr ); ++i ) - { - c = c->maybeGetAttr( std::get( path.path[i] ) ); - } - if ( c != nullptr ) { rsl.push_back( std::move( (Cursor) c ) ); } - } - } - } - else /* Relative */ - { - for ( const auto & prefix : this->getFlakePrefixCursors() ) - { - MaybeCursor c = prefix; - for ( size_t i = 0; ( i < path.size() ) && ( c != nullptr ); ++i ) - { - c = c->maybeGetAttr( std::get( path.path[i] ) ); - } - if ( c != nullptr ) { rsl.push_back( std::move( (Cursor) c ) ); } - } - } - return rsl; -} - - /* -------------------------------------------------------------------------- */ } /* End namespace `flox::resolve' */ diff --git a/tests/drv-cache.cc b/tests/drv-cache.cc index 88d6282..55508bf 100644 --- a/tests/drv-cache.cc +++ b/tests/drv-cache.cc @@ -97,18 +97,6 @@ test_CachedPackageFromInfo1( DrvDb * cache ) } -/* -------------------------------------------------------------------------- */ - bool -test_FloxFlake_getActualFlakeAttrPathPrefixes1( ResolverState & rs ) -{ - std::optional> mf = rs.getInput( "nixpkgs" ); - nix::ref flake = mf.value(); - std::list> prefixes = - flake->getActualFlakeAttrPathPrefixes(); - return prefixes.size() == defaultSystems.size(); -} - - /* -------------------------------------------------------------------------- */ int @@ -141,7 +129,6 @@ main( int argc, char * argv[], char ** envp ) RUN_TEST( CachedPackageFromDb1, cache ); RUN_TEST( CachedPackageFromDb2, cache, prefs ); RUN_TEST( CachedPackageFromInfo1, cache ); - RUN_TEST( FloxFlake_getActualFlakeAttrPathPrefixes1, rs ); delete cache; diff --git a/tests/resolve.cc b/tests/resolve.cc index e2633df..e74bbbc 100644 --- a/tests/resolve.cc +++ b/tests/resolve.cc @@ -28,19 +28,6 @@ test_ResolverStateLocking1() } -/* -------------------------------------------------------------------------- */ - - bool -test_getActualFlakeAttrPathPrefixes() -{ - Inputs inputs( (nlohmann::json) { { "nixpkgs", nixpkgsRef } } ); - Preferences prefs; - ResolverState rs( inputs, prefs ); - auto ps = rs.getInputs().at( "nixpkgs" )->getActualFlakeAttrPathPrefixes(); - return ps.size() == defaultSystems.size(); -} - - /* -------------------------------------------------------------------------- */ /* Use relative path. */ @@ -105,7 +92,6 @@ main( int argc, char * argv[], char ** envp ) # define RUN_TEST( ... ) _RUN_TEST( ec, __VA_ARGS__ ) RUN_TEST( ResolverStateLocking1 ); - RUN_TEST( getActualFlakeAttrPathPrefixes ); RUN_TEST( resolveInInput1 ); RUN_TEST( resolveInInput2 ); RUN_TEST( resolve_V2_1 );