mirror of https://github.com/vitalif/grive2
Converts paths to canonical paths, which makes it work with relative path inputs
parent
c41072c13d
commit
a592721258
|
@ -323,24 +323,16 @@ void State::ChangeStamp( long cstamp )
|
|||
|
||||
bool State::Move( Syncer* syncer, fs::path old_p, fs::path new_p, fs::path grive_root )
|
||||
{
|
||||
//If paths are relative, convert to absolute
|
||||
if( old_p.is_relative() )
|
||||
old_p = fs::current_path() / old_p;
|
||||
if ( new_p.is_relative() )
|
||||
new_p = fs::current_path() / new_p;
|
||||
if ( grive_root.is_relative() )
|
||||
grive_root = fs::current_path() / grive_root;
|
||||
//Convert paths to canonical representations
|
||||
//Also seems to remove trailing / at the end of directory paths
|
||||
old_p = fs::canonical( old_p );
|
||||
new_p = fs::canonical( new_p );
|
||||
grive_root = fs::canonical( grive_root );
|
||||
|
||||
//Fails if source file doesn't exist, or if destination file already
|
||||
//exists and is not a directory.
|
||||
if ( (fs::exists(new_p) && !fs::is_directory(new_p) ) || !fs::exists(old_p) )
|
||||
return false;
|
||||
|
||||
//If path ends in a /, remove the /
|
||||
if ( new_p.string()[ new_p.string().size() - 1 ] == '/' )
|
||||
new_p = new_p.string().substr( 0, new_p.string().size() - 1 );
|
||||
if ( old_p.string()[ old_p.string().size() - 1 ] == '/' )
|
||||
old_p = old_p.string().substr( 0, old_p.string().size() - 1 );
|
||||
if ( grive_root.string()[ grive_root.string().size() - 1 ] == '/' )
|
||||
grive_root = grive_root.string().substr( 0, grive_root.string().size() - 1 );
|
||||
|
||||
//If new path is an existing directory, move the file into the directory
|
||||
//instead of trying to rename it
|
||||
|
@ -349,6 +341,7 @@ bool State::Move( Syncer* syncer, fs::path old_p, fs::path new_p, fs::path grive
|
|||
}
|
||||
|
||||
//Get the paths relative to grive root.
|
||||
//Just finds the substring from the end of the grive_root to the end of the path
|
||||
//+1s are to exclude slash at beginning of relative path
|
||||
int start = grive_root.string().size() + 1;
|
||||
int nLen = new_p.string().size() - (grive_root.string().size() + 1);
|
||||
|
|
Loading…
Reference in New Issue