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).
pull/40/head
Vitaliy Filippov 2015-10-08 01:41:33 +03:00
parent f288c559c6
commit d9300c953e
2 changed files with 13 additions and 6 deletions

View File

@ -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( )

View File

@ -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() ) ;