Organize temporary files under GRAPHENE_TEMPDIR (or /tmp/graphene-tmp if undefined)

This commit is contained in:
theoreticalbts 2015-07-13 14:56:29 -04:00
parent 41de02aadb
commit e876c5fb81
8 changed files with 95 additions and 21 deletions

View file

@ -9,9 +9,12 @@ endif(NOT GRAPHENE_GIT_REVISION_DESCRIPTION)
file(GLOB headers "include/graphene/utilities/*.hpp")
set(sources key_conversion.cpp string_escape.cpp
words.cpp
${headers})
set(sources
key_conversion.cpp
string_escape.cpp
tempdir.cpp
words.cpp
${headers})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp" @ONLY)
list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp")

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, Cryptonomex, Inc.
* All rights reserved.
*
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
* are permitted until September 8, 2015, provided that the following conditions are met:
*
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <cstdlib>
#include <fc/filesystem.hpp>
namespace graphene { namespace utilities {
fc::path temp_directory_path();
} } // graphene::utilities

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2015, Cryptonomex, Inc.
* All rights reserved.
*
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
* are permitted until September 8, 2015, provided that the following conditions are met:
*
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <graphene/utilities/tempdir.hpp>
#include <cstdlib>
namespace graphene { namespace utilities {
fc::path temp_directory_path()
{
const char* graphene_tempdir = getenv("GRAPHENE_TEMPDIR");
if( graphene_tempdir != nullptr )
return fc::path( graphene_tempdir );
return fc::temp_directory_path() / "graphene-tmp";
}
} } // graphene::utilities

View file

@ -20,6 +20,8 @@
#include <graphene/time/time.hpp>
#include <graphene/utilities/tempdir.hpp>
#include <graphene/account_history/account_history_plugin.hpp>
#include <fc/thread/thread.hpp>
@ -36,8 +38,8 @@ BOOST_AUTO_TEST_CASE( two_node_network )
using namespace graphene::chain;
using namespace graphene::app;
try {
fc::temp_directory app_dir;
fc::temp_directory app2_dir;
fc::temp_directory app_dir( graphene::utilities::temp_directory_path() );
fc::temp_directory app2_dir( graphene::utilities::temp_directory_path() );
fc::temp_file genesis_json;
// TODO: Time should be read from the blockchain

View file

@ -17,6 +17,7 @@
*/
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/utilities/tempdir.hpp>
#include <graphene/time/time.hpp>
@ -58,7 +59,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench )
genesis_state.initial_accounts.emplace_back("target"+fc::to_string(i),
public_key_type(fc::ecc::private_key::regenerate(fc::digest(i)).get_public_key()));
fc::temp_directory data_dir(fc::current_path());
fc::temp_directory data_dir( graphene::utilities::temp_directory_path() );
{
database db;

View file

@ -30,6 +30,8 @@
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/utilities/tempdir.hpp>
#include <fc/crypto/digest.hpp>
#include <fc/smart_ref_impl.hpp>
@ -285,7 +287,7 @@ void database_fixture::verify_account_history_plugin_index( )const
void database_fixture::open_database()
{
if( !data_dir ) {
data_dir = fc::temp_directory();
data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() );
db.open(data_dir->path(), [this]{return genesis_state;});
}
}

View file

@ -26,6 +26,8 @@
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/witness_schedule_object.hpp>
#include <graphene/utilities/tempdir.hpp>
#include <fc/crypto/digest.hpp>
#include "../common/database_fixture.hpp"
@ -58,7 +60,7 @@ BOOST_AUTO_TEST_SUITE(block_tests)
BOOST_AUTO_TEST_CASE( block_database_test )
{
try {
fc::temp_directory data_dir;
fc::temp_directory data_dir( graphene::utilities::temp_directory_path() );
block_database bdb;
bdb.open( data_dir.path() );
@ -119,7 +121,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks )
{
try {
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
fc::temp_directory data_dir;
fc::temp_directory data_dir( graphene::utilities::temp_directory_path() );
signed_block b;
now += GRAPHENE_DEFAULT_BLOCK_INTERVAL;
@ -166,7 +168,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks )
BOOST_AUTO_TEST_CASE( undo_block )
{
try {
fc::temp_directory data_dir;
fc::temp_directory data_dir( graphene::utilities::temp_directory_path() );
{
database db;
db.open(data_dir.path(), make_genesis);
@ -204,8 +206,8 @@ BOOST_AUTO_TEST_CASE( undo_block )
BOOST_AUTO_TEST_CASE( fork_blocks )
{
try {
fc::temp_directory data_dir1;
fc::temp_directory data_dir2;
fc::temp_directory data_dir1( graphene::utilities::temp_directory_path() );
fc::temp_directory data_dir2( graphene::utilities::temp_directory_path() );
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
database db1;
@ -271,7 +273,7 @@ BOOST_AUTO_TEST_CASE( undo_pending )
{
try {
fc::time_point_sec now(GRAPHENE_TESTING_GENESIS_TIMESTAMP);
fc::temp_directory data_dir;
fc::temp_directory data_dir( graphene::utilities::temp_directory_path() );
{
database db;
db.open(data_dir.path(), make_genesis);
@ -335,8 +337,8 @@ BOOST_AUTO_TEST_CASE( undo_pending )
BOOST_AUTO_TEST_CASE( switch_forks_undo_create )
{
try {
fc::temp_directory dir1,
dir2;
fc::temp_directory dir1( graphene::utilities::temp_directory_path() ),
dir2( graphene::utilities::temp_directory_path() );
database db1,
db2;
db1.open(dir1.path(), make_genesis);
@ -393,8 +395,8 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions )
{
try {
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
fc::temp_directory dir1,
dir2;
fc::temp_directory dir1( graphene::utilities::temp_directory_path() ),
dir2( graphene::utilities::temp_directory_path() );
database db1,
db2;
db1.open(dir1.path(), make_genesis);
@ -445,8 +447,8 @@ BOOST_AUTO_TEST_CASE( tapos )
{
try {
fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP );
fc::temp_directory dir1,
dir2;
fc::temp_directory dir1( graphene::utilities::temp_directory_path() ),
dir2( graphene::utilities::temp_directory_path() );
database db1,
db2;
db1.open(dir1.path(), make_genesis);

View file

@ -19,6 +19,8 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/balance_object.hpp>
@ -28,7 +30,8 @@
#include <graphene/chain/worker_evaluator.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/utilities/tempdir.hpp>
#include <fc/crypto/digest.hpp>
@ -970,7 +973,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test )
{ try {
// Intentionally overriding the fixture's db; I need to control genesis on this one.
database db;
fc::temp_directory td;
fc::temp_directory td( graphene::utilities::temp_directory_path() );
genesis_state.initial_balances.push_back({generate_private_key("n").get_public_key(), GRAPHENE_SYMBOL, 1});
genesis_state.initial_balances.push_back({generate_private_key("x").get_public_key(), GRAPHENE_SYMBOL, 1});
auto starting_time = time_point_sec((time_point::now().sec_since_epoch() / GRAPHENE_DEFAULT_BLOCK_INTERVAL + 1) *