don't delete the file if its parent folder will be deleted

pull/40/head
Nestal Wan 2012-06-03 14:44:09 +08:00
parent 5edd71b69e
commit 3d7ad69915
1 changed files with 13 additions and 5 deletions

View File

@ -68,6 +68,9 @@ void Resource::FromRemoteFolder( const Entry& remote, const DateTime& last_sync
{ {
fs::path path = Path() ; fs::path path = Path() ;
if ( remote.CreateLink().empty() )
Log( "folder %1% is read-only", path, log::verbose ) ;
// already sync // already sync
if ( fs::is_directory( path ) ) if ( fs::is_directory( path ) )
{ {
@ -86,7 +89,7 @@ void Resource::FromRemoteFolder( const Entry& remote, const DateTime& last_sync
} }
else else
{ {
Log( "folder %1% is created in local", path, log::verbose ) ; Log( "folder %1% is created in remote", path, log::verbose ) ;
fs::create_directories( path ) ; fs::create_directories( path ) ;
m_state = sync ; m_state = sync ;
} }
@ -290,8 +293,13 @@ void Resource::Sync( http::Agent *http, const http::Headers& auth )
break ; break ;
case local_deleted : case local_deleted :
Log( "sync %1% deleted in local. deleting remote", Path(), log::verbose ) ; if ( m_parent->m_state == local_deleted )
DeleteRemote( http, auth ) ; Log( "sync %1% parent deleted in local.", Path(), log::verbose ) ;
else
{
Log( "sync %1% deleted in local. deleting remote", Path(), log::verbose ) ;
DeleteRemote( http, auth ) ;
}
break ; break ;
case local_changed : case local_changed :
@ -347,7 +355,6 @@ void Resource::DeleteRemote( http::Agent *http, const http::Headers& auth )
{ {
http::Headers hdr( auth ) ; http::Headers hdr( auth ) ;
hdr.push_back( "If-Match: " + m_entry.ETag() ) ; hdr.push_back( "If-Match: " + m_entry.ETag() ) ;
http::StringResponse str ; http::StringResponse str ;
try try
{ {
@ -355,8 +362,9 @@ void Resource::DeleteRemote( http::Agent *http, const http::Headers& auth )
} }
catch ( Exception& ) catch ( Exception& )
{ {
// don't rethrow here. there are some cases that I don't know why
// the delete will fail.
Trace( "response = %1%", str.Response() ) ; Trace( "response = %1%", str.Response() ) ;
throw ;
} }
} }