swap.cpp 720 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <iostream>
  2. #include "simple/file.hpp"
  3. using namespace simple;
  4. using namespace simple::file::operators;
  5. void swap(const std::string& onePath, const std::string& otherPath)
  6. {
  7. if(onePath == otherPath)
  8. return;
  9. auto one = file::dump(file::bropex(onePath));
  10. auto other = file::dump(file::bropex(otherPath));
  11. file::bwopex(onePath) <<= other;
  12. file::bwopex(otherPath) <<= one;
  13. }
  14. int main(int argc, char const* argv[]) try
  15. {
  16. if(argc < 3)
  17. {
  18. std::cout << "Expecting two arguments, got " << argc - 1 << '\n';
  19. return -1;
  20. }
  21. if(argc > 3)
  22. std::cout << "Ignoring all arguments after the first 2" << '\n';
  23. swap(argv[1], argv[2]);
  24. return 0;
  25. }
  26. catch(...)
  27. {
  28. if(errno)
  29. std::perror("Oh nooo!");
  30. throw;
  31. }