//////////////////////////////////////////////////////////////////////////////// // taskwarrior - a command line task list manager. // // Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. // All rights reserved. // // This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation; either version 2 of the License, or (at your option) any later // version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // details. // // You should have received a copy of the GNU General Public License along with // this program; if not, write to the // // Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, // Boston, MA // 02110-1301 // USA // //////////////////////////////////////////////////////////////////////////////// #define L10N // Localization complete. #include #include #include #include #include #include #include #include extern Context context; //////////////////////////////////////////////////////////////////////////////// CmdPull::CmdPull () { _keyword = "pull"; _usage = "task pull URL"; _description = STRING_CMD_PULL_USAGE; _read_only = true; _displays_id = false; } //////////////////////////////////////////////////////////////////////////////// int CmdPull::execute (std::string& output) { std::vector words = context.a3.extract_words (); std::string file; if (words.size ()) file = words[0]; Uri uri (file, "pull"); uri.parse (); if (uri._data.length ()) { Directory location (context.config.get ("data.location")); if (! uri.append ("{pending,undo,completed}.data")) throw format (STRING_CMD_PULL_NOT_DIR, uri._path); Transport* transport; if ((transport = Transport::getTransport (uri)) != NULL) { transport->recv (location._data + "/"); delete transport; } 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 (STRING_CMD_PULL_SAME); // copy files locally // remove {pending,undo,completed}.data uri._path = uri.parent(); Path path1 (uri._path + "undo.data"); Path path2 (uri._path + "pending.data"); Path path3 (uri._path + "completed.data"); if (path1.exists() && path2.exists() && path3.exists()) { // if (confirm ("xxxxxxxxxxxxx")) // { 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::ifstream ifile2 (path2._data.c_str() , std::ios_base::binary); ofile2 << ifile2.rdbuf(); std::ofstream ofile3 ((location._data + "/completed.data").c_str(), std::ios_base::binary); std::ifstream ifile3 (path3._data.c_str() , std::ios_base::binary); ofile3 << ifile3.rdbuf(); // } } else { throw format (STRING_CMD_PULL_MISSING, uri._path); } } output += format (STRING_CMD_PULL_TRANSFERRED, uri._data) + "\n"; } else throw std::string (STRING_CMD_PULL_NO_URI); return 0; } ////////////////////////////////////////////////////////////////////////////////