1575 } |
1575 } |
1576 |
1576 |
1577 static int cmd_operation_on_resources(CmdArgs* a, |
1577 static int cmd_operation_on_resources(CmdArgs* a, |
1578 int(*operation)(DavResource*), |
1578 int(*operation)(DavResource*), |
1579 const char* command, |
1579 const char* command, |
1580 const char* message) { |
1580 const char* message, |
|
1581 DavBool check_key) |
|
1582 { |
1581 if(a->argc < 1) { |
1583 if(a->argc < 1) { |
1582 fprintf(stderr, "Too few arguments\n"); |
1584 fprintf(stderr, "Too few arguments\n"); |
1583 fprintf(stderr, "Usage: dav %s\n", find_usage_str(command)); |
1585 fprintf(stderr, "Usage: dav %s\n", find_usage_str(command)); |
1584 return -1; |
1586 return -1; |
1585 } |
1587 } |
1596 goto cmd_oponres_exit; |
1598 goto cmd_oponres_exit; |
1597 } |
1599 } |
1598 |
1600 |
1599 set_session_lock(sn, a); |
1601 set_session_lock(sn, a); |
1600 |
1602 |
1601 if(check_encryption_key(a, sn)) { |
1603 if(check_key && check_encryption_key(a, sn)) { |
1602 goto cmd_oponres_exit; |
1604 goto cmd_oponres_exit; |
1603 } |
1605 } |
1604 |
1606 |
1605 DavResource *res = dav_resource_new(sn, path); |
1607 DavResource *res = dav_resource_new(sn, path); |
1606 assert(!!res); |
1608 assert(!!res); |
1632 return exit_code; |
1634 return exit_code; |
1633 } |
1635 } |
1634 |
1636 |
1635 int cmd_remove(CmdArgs *a) { |
1637 int cmd_remove(CmdArgs *a) { |
1636 return cmd_operation_on_resources(a, dav_delete, |
1638 return cmd_operation_on_resources(a, dav_delete, |
1637 "remove", "delete resource"); |
1639 "remove", "delete resource", FALSE); |
1638 } |
1640 } |
1639 |
1641 |
1640 int cmd_mkdir(CmdArgs *a) { |
1642 int cmd_mkdir(CmdArgs *a) { |
1641 return cmd_operation_on_resources(a, dav_create_col, |
1643 return cmd_operation_on_resources(a, dav_create_col, |
1642 "mkdir", "create collection"); |
1644 "mkdir", "create collection", TRUE); |
1643 } |
1645 } |
1644 |
1646 |
1645 int cmd_move(CmdArgs *a, int cp) { |
1647 int cmd_move(CmdArgs *a, int cp) { |
1646 const char* actionstr = cp ? "copy" : "move"; |
1648 const char* actionstr = cp ? "copy" : "move"; |
1647 |
1649 |