irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rmdirUtil.cpp
Go to the documentation of this file.
1 #include "rmdirUtil.h"
2 #include "rmUtil.h"
3 #include "rodsPath.h"
4 #include "rodsErrorTable.h"
5 #include "rodsLog.h"
6 #include "rcGlobalExtern.h"
7 #include "rodsPath.h"
8 #include "rcMisc.h"
9 
10 #include "filesystem.hpp"
11 
12 #include "boost/filesystem.hpp"
13 
14 #include <iostream>
15 
16 int
18  rodsArguments_t *myRodsArgs,
19  int treatAsPathname,
20  int numColls,
21  rodsPath_t collPaths[] ) {
22  if ( numColls <= 0 ) {
23  return USER__NULL_INPUT_ERR;
24  }
25 
26  int status = 0;
27 
28  for ( int i = 0; i < numColls; ++i ) {
29  status = rmdirCollUtil( conn, myRodsArgs, treatAsPathname, collPaths[i] );
30  }
31 
32  return status;
33 }
34 
36  rodsArguments_t *myRodsArgs,
37  int treatAsPathname,
38  rodsPath_t collPath)
39 {
40  namespace fs = irods::experimental::filesystem;
41 
42  fs::path abs_path = collPath.outPath;
43 
44  // Handle "-p".
45  if (treatAsPathname) {
46  try {
47  const auto options = myRodsArgs->force
49  : fs::remove_options::none;
50 
51  // Iterate over the elements in the path. This guarantees that no collections
52  // above the ones provided are touched.
53  for (auto&& _ : fs::path{collPath.inPath}) {
54  const auto status = fs::client::status(*conn, abs_path);
55 
56  if (!fs::client::exists(status)) {
57  std::cerr << "Failed to remove [" << abs_path << "]: Collection does not exist\n";
58  return 0;
59  }
60 
62  std::cerr << "Failed to remove [" << abs_path << "]: Path does not point to a collection\n";
63  return 0;
64  }
65 
66  if (!fs::client::is_empty(*conn, abs_path)) {
67  std::cerr << "Failed to remove [" << abs_path << "]: Collection is not empty\n";
68  return 0;
69  }
70 
71  fs::client::remove(*conn, abs_path, options);
72  abs_path = abs_path.parent_path();
73 
74  static_cast<void>(_); // Unused
75  }
76  }
77  catch (const fs::filesystem_error& e) {
78  std::cerr << "Error: " << e.what() << '\n';
79  }
80 
81  return 0;
82  }
83 
84  if (!fs::client::is_collection(*conn, abs_path)) {
85  std::cout << "Failed to remove [" << abs_path << "]: Collection does not exist\n";
86  return 0;
87  }
88 
89  // check to make sure it's not /, /home, or /home/username?
90  // XXXXX
91 
92  if (!fs::client::is_empty(*conn, abs_path)) {
93  std::cout << "Failed to remove [" << abs_path << "]: Collection is not empty\n";
94  return 0;
95  }
96 
97  collInp_t collInp;
98  dataObjInp_t dataObjInp;
99 
100  initCondForRm( myRodsArgs, &dataObjInp, &collInp );
101  rstrcpy( collInp.collName, collPath.outPath, MAX_NAME_LEN );
102 
103  const int status = rcRmColl( conn, &collInp, myRodsArgs->verbose );
104 
105  if (status < 0) {
106  std::cout << "rmdirColl: rcRmColl failed with error " << status << '\n';
107  }
108 
109  return status;
110 }
111 
rcComm_t
Definition: rcConnect.h:95
irods::experimental::filesystem::client::is_collection
auto is_collection(object_status _s) noexcept -> bool
Definition: filesystem.cpp:600
rodsPath.h
rodsArguments_t
Definition: parseCommandLine.h:14
CollInp
Definition: dataObjInpOut.h:157
rodsArguments_t::verbose
int verbose
Definition: parseCommandLine.h:107
irods::experimental::administration::client::v1::exists
auto exists(rcComm_t &conn, const user &user) -> bool
Definition: user_administration.cpp:359
rcMisc.h
RodsPath::inPath
char inPath[(1024+64)]
Definition: rodsPath.h:23
rmdirUtil.h
filesystem.hpp
deploy_schemas_locally._
_
Definition: deploy_schemas_locally.py:63
rcGlobalExtern.h
rmdirUtil
int rmdirUtil(rcComm_t *conn, rodsArguments_t *myRodsArgs, int treatAsPathname, int numColls, rodsPath_t collPaths[])
Definition: rmdirUtil.cpp:17
irods::experimental::filesystem
Definition: collection_entry.hpp:12
rmUtil.h
DataObjInp
Definition: dataObjInpOut.h:65
no_trash
bool no_trash
Definition: filesystem.cpp:250
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
deploy_schemas_locally.options
options
Definition: deploy_schemas_locally.py:63
irods::experimental::filesystem::client::is_empty
auto is_empty(rcComm_t &_comm, const path &_p) -> bool
Definition: filesystem.cpp:610
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsLog.h
rcRmColl
int rcRmColl(rcComm_t *conn, collInp_t *rmCollInp, int vFlag)
Definition: rcRmColl.cpp:79
rodsArguments_t::force
int force
Definition: parseCommandLine.h:38
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
initCondForRm
int initCondForRm(rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
Definition: rmUtil.cpp:102
irods::experimental::filesystem::client::remove
auto remove(rcComm_t &_comm, const path &_p, remove_options _opts=remove_options::none) -> bool
Definition: filesystem.cpp:699
rmdirCollUtil
int rmdirCollUtil(rcComm_t *conn, rodsArguments_t *myRodsArgs, int treatAsPathname, rodsPath_t collPath)
Definition: rmdirUtil.cpp:35
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
rodsErrorTable.h
RodsPath
Definition: rodsPath.h:18
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247