mirror of https://github.com/vitalif/grive2
recursive delete handling for remote_deleted
parent
197abfdea6
commit
28b32c6f43
|
@ -341,8 +341,13 @@ void Resource::Sync( http::Agent *http, const http::Header& auth )
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case remote_deleted :
|
case remote_deleted :
|
||||||
Log( "sync %1% deleted in remote. deleting local", Path(), log::verbose ) ;
|
if ( m_parent->m_state == remote_deleted )
|
||||||
DeleteLocal() ;
|
Log( "sync %1% parent deleted in remote.", Path(), log::verbose ) ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log( "sync %1% deleted in remote. deleting local", Path(), log::verbose ) ;
|
||||||
|
DeleteLocal() ;
|
||||||
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case sync :
|
case sync :
|
||||||
|
@ -357,23 +362,24 @@ void Resource::Sync( http::Agent *http, const http::Header& auth )
|
||||||
/// this function doesn't really remove the local file. it renames it.
|
/// this function doesn't really remove the local file. it renames it.
|
||||||
void Resource::DeleteLocal()
|
void Resource::DeleteLocal()
|
||||||
{
|
{
|
||||||
|
static const boost::format trash_file( "%1%-%2%" ) ;
|
||||||
|
|
||||||
assert( m_parent != 0 ) ;
|
assert( m_parent != 0 ) ;
|
||||||
fs::path parent = m_parent->Path() ;
|
fs::path parent = m_parent->Path() ;
|
||||||
fs::path dest = parent / ( "." + Name() ) ;
|
fs::path dest = ".trash" / parent / Name() ;
|
||||||
|
|
||||||
std::size_t idx = 1 ;
|
std::size_t idx = 1 ;
|
||||||
while ( fs::exists( dest ) && idx != 0 )
|
while ( fs::exists( dest ) && idx != 0 )
|
||||||
{
|
dest = ".trash" / parent / (boost::format(trash_file) % Name() % idx++).str() ;
|
||||||
std::ostringstream oss ;
|
|
||||||
oss << '.' << Name() << "-" << idx++ ;
|
|
||||||
dest = parent / oss.str() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// wrap around! just remove the file
|
// wrap around! just remove the file
|
||||||
if ( idx == 0 )
|
if ( idx == 0 )
|
||||||
fs::remove_all( Path() ) ;
|
fs::remove_all( Path() ) ;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
fs::create_directories( dest.parent_path() ) ;
|
||||||
fs::rename( Path(), dest ) ;
|
fs::rename( Path(), dest ) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::DeleteRemote( http::Agent *http, const http::Header& auth )
|
void Resource::DeleteRemote( http::Agent *http, const http::Header& auth )
|
||||||
|
|
Loading…
Reference in New Issue