From d9300c953e25c145d30ecb894f58a280aa987656 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 8 Oct 2015 01:41:33 +0300 Subject: [PATCH] Fix .trash and .grive_state in drive location when used with -p option Previously .trash and .grive_state were incorrectly placed in the current working directory instead of synced root directory (-p). --- libgrive/src/base/Drive.cc | 2 +- libgrive/src/base/Resource.cc | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libgrive/src/base/Drive.cc b/libgrive/src/base/Drive.cc index a8efb8a..7aa282a 100644 --- a/libgrive/src/base/Drive.cc +++ b/libgrive/src/base/Drive.cc @@ -85,7 +85,7 @@ void Drive::FromChange( const Entry& entry ) void Drive::SaveState() { - m_state.Write( state_file ) ; + m_state.Write( m_root / state_file ) ; } void Drive::SyncFolders( ) diff --git a/libgrive/src/base/Resource.cc b/libgrive/src/base/Resource.cc index e206ebc..32c7752 100644 --- a/libgrive/src/base/Resource.cc +++ b/libgrive/src/base/Resource.cc @@ -461,13 +461,20 @@ void Resource::DeleteLocal() static const boost::format trash_file( "%1%-%2%" ) ; assert( m_parent != 0 ) ; - fs::path parent = m_parent->Path() ; - fs::path dest = ".trash" / parent / Name() ; - + Resource* p = m_parent; + fs::path destdir; + while ( !p->IsRoot() ) + { + destdir = p->Name() / destdir; + p = p->Parent(); + } + destdir = p->Path() / ".trash" / destdir; + + fs::path dest = destdir / Name(); std::size_t idx = 1 ; while ( fs::exists( dest ) && idx != 0 ) - dest = ".trash" / parent / (boost::format(trash_file) % Name() % idx++).str() ; - + dest = destdir / (boost::format(trash_file) % Name() % idx++).str() ; + // wrap around! just remove the file if ( idx == 0 ) fs::remove_all( Path() ) ;