Sync
- Added Path::operator== for expanded path comparisons. Why was that not already implemented? - Added checks that the push/pull destination is not equal to rc.data.location. That would be bad. - Added comments, tweaked the wording on some messages. Stubbed out confirmation of pull overwrite, while I think about it.
This commit is contained in:
@@ -66,6 +66,12 @@ Path& Path::operator= (const Path& other)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Path::operator== (const Path& other)
|
||||||
|
{
|
||||||
|
return data == other.data;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Path::operator std::string () const
|
Path::operator std::string () const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public:
|
|||||||
virtual ~Path ();
|
virtual ~Path ();
|
||||||
|
|
||||||
Path& operator= (const Path&);
|
Path& operator= (const Path&);
|
||||||
|
bool operator== (const Path&);
|
||||||
operator std::string () const;
|
operator std::string () const;
|
||||||
|
|
||||||
std::string name () const;
|
std::string name () const;
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ void handleMerge (std::string& outs)
|
|||||||
|| (bAutopush) )
|
|| (bAutopush) )
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
handlePush(out);
|
handlePush (out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -642,6 +642,8 @@ void handleMerge (std::string& outs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Transfers the local data (from rc.location.data) to the remote path. Because
|
||||||
|
// this is potentially on another machine, no checking can be performed.
|
||||||
void handlePush (std::string& outs)
|
void handlePush (std::string& outs)
|
||||||
{
|
{
|
||||||
if (context.hooks.trigger ("pre-push-command"))
|
if (context.hooks.trigger ("pre-push-command"))
|
||||||
@@ -663,9 +665,14 @@ void handlePush (std::string& outs)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Verify that files are not being copied from rc.data.location to the
|
||||||
|
// same place.
|
||||||
|
if (Directory (uri.path) == Directory (context.config.get ("data.location")))
|
||||||
|
throw std::string ("Cannot push files when the source and destination are the same.");
|
||||||
|
|
||||||
// copy files locally
|
// copy files locally
|
||||||
if (!uri.is_directory())
|
if (! Path (uri.data).is_directory ())
|
||||||
throw std::string ("The uri '") + uri.path + "' does not appear to be a directory.";
|
throw std::string ("The uri '") + uri.path + "' is not a local directory.";
|
||||||
|
|
||||||
std::ifstream ifile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
|
std::ifstream ifile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
|
||||||
std::ofstream ofile1 ((uri.path + "undo.data").c_str(), std::ios_base::binary);
|
std::ofstream ofile1 ((uri.path + "undo.data").c_str(), std::ios_base::binary);
|
||||||
@@ -703,8 +710,9 @@ void handlePull (std::string& outs)
|
|||||||
{
|
{
|
||||||
Directory location (context.config.get ("data.location"));
|
Directory location (context.config.get ("data.location"));
|
||||||
|
|
||||||
if (!uri.append ("{pending,undo,completed}.data"))
|
if (! uri.append ("{pending,undo,completed}.data") ||
|
||||||
throw std::string ("The uri '") + uri.path + "' does not appear to be a directory.";
|
! Path (uri.data).is_directory ())
|
||||||
|
throw std::string ("The uri '") + uri.path + "' is not a local directory.";
|
||||||
|
|
||||||
Transport* transport;
|
Transport* transport;
|
||||||
if ((transport = Transport::getTransport (uri)) != NULL)
|
if ((transport = Transport::getTransport (uri)) != NULL)
|
||||||
@@ -714,6 +722,11 @@ void handlePull (std::string& outs)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Verify that files are not being copied from rc.data.location to the
|
||||||
|
// same place.
|
||||||
|
if (Directory (uri.path) == Directory (context.config.get ("data.location")))
|
||||||
|
throw std::string ("Cannot pull files when the source and destination are the same.");
|
||||||
|
|
||||||
// copy files locally
|
// copy files locally
|
||||||
|
|
||||||
// remove {pending,undo,completed}.data
|
// remove {pending,undo,completed}.data
|
||||||
@@ -725,17 +738,20 @@ void handlePull (std::string& outs)
|
|||||||
|
|
||||||
if (path1.exists() && path2.exists() && path3.exists())
|
if (path1.exists() && path2.exists() && path3.exists())
|
||||||
{
|
{
|
||||||
std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
|
// if (confirm ("xxxxxxxxxxxxx"))
|
||||||
std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary);
|
// {
|
||||||
ofile1 << ifile1.rdbuf();
|
std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
|
||||||
|
std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary);
|
||||||
|
ofile1 << ifile1.rdbuf();
|
||||||
|
|
||||||
std::ofstream ofile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary);
|
std::ofstream ofile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary);
|
||||||
std::ifstream ifile2 (path2.data.c_str() , std::ios_base::binary);
|
std::ifstream ifile2 (path2.data.c_str() , std::ios_base::binary);
|
||||||
ofile2 << ifile2.rdbuf();
|
ofile2 << ifile2.rdbuf();
|
||||||
|
|
||||||
std::ofstream ofile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary);
|
std::ofstream ofile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary);
|
||||||
std::ifstream ifile3 (path3.data.c_str() , std::ios_base::binary);
|
std::ifstream ifile3 (path3.data.c_str() , std::ios_base::binary);
|
||||||
ofile3 << ifile3.rdbuf();
|
ofile3 << ifile3.rdbuf();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user