Skip to content

Commit

Permalink
Fix .trash and .grive_state in drive location when used with -p option
Browse files Browse the repository at this point in the history
Previously .trash and .grive_state were incorrectly placed in the current
working directory instead of synced root directory (-p).
  • Loading branch information
vitalif committed Oct 7, 2015
1 parent f288c55 commit d9300c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libgrive/src/base/Drive.cc
Expand Up @@ -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( )
Expand Down
17 changes: 12 additions & 5 deletions libgrive/src/base/Resource.cc
Expand Up @@ -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() ) ;
Expand Down

0 comments on commit d9300c9

Please sign in to comment.