Skip to content

Commit 6b204f8

Browse files
committed
CLI: Add force option when creating a symlink. This will allow to overwrite an already defined symlink
Closes EOS-6392
1 parent dca0e04 commit 6b204f8

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

console/commands/com_file.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ com_file(char* arg1)
308308
in += path.c_str();
309309
in += "&mgm.file.target=";
310310
in += fsid1.c_str();
311+
312+
if (option.find("f") != STR_NPOS) {
313+
in += "&mgm.file.force=1";
314+
}
311315
}
312316

313317
if (cmd == "share") {
@@ -1123,9 +1127,12 @@ com_file(char* arg1)
11231127
"file replicate [<path>|fid:<fid-dec>|fxid:<fid-hex>] <fsid1> <fsid2> :\n");
11241128
fprintf(stdout,
11251129
" replicate file <path> part on <fsid1> to <fsid2>\n");
1126-
fprintf(stdout, "file symlink <name> <link-name> :\n");
1130+
fprintf(stdout,
1131+
"file symlink [-f] <name> <link-name> :\n");
11271132
fprintf(stdout,
11281133
" create a symlink with <name> pointing to <link-name>\n");
1134+
fprintf(stdout,
1135+
" -f : force overwrite\n");
11291136
fprintf(stdout, "file tag <path>|fid:<fid-dec>|fxid:<fid-hex> +|-|~<fsid> :\n");
11301137
fprintf(stdout,
11311138
" add/remove/unlink a filesystem location to/from a file in the location index - attention this does not move any data!\n");

mgm/XrdMgmOfs.hh

+4-2
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ public:
673673
XrdOucErrInfo& out_error,
674674
const XrdSecEntity* client = 0,
675675
const char* opaqueO = 0,
676-
const char* opaqueN = 0);
676+
const char* opaqueN = 0,
677+
bool overwrite = false);
677678

678679
// ---------------------------------------------------------------------------
679680
// symlink file/dir by vid
@@ -694,7 +695,8 @@ public:
694695
XrdOucErrInfo& out_error,
695696
eos::common::VirtualIdentity& vid,
696697
const char* opaqueO = 0,
697-
const char* opaqueN = 0);
698+
const char* opaqueN = 0,
699+
bool overwrite = false);
698700

699701
// ---------------------------------------------------------------------------
700702
// read symbolic link

mgm/XrdMgmOfs/Link.cc

+13-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ XrdMgmOfs::symlink(const char* source_name,
3434
XrdOucErrInfo& error,
3535
const XrdSecEntity* client,
3636
const char* infoO,
37-
const char* infoN)
37+
const char* infoN,
38+
bool overwrite)
3839
/*----------------------------------------------------------------------------*/
3940
/*
4041
* @brief symlink a file or directory
@@ -100,7 +101,7 @@ XrdMgmOfs::symlink(const char* source_name,
100101
MAYREDIRECT;
101102
}
102103
return symlink(sourcen.c_str(), targetn.c_str(), error, vid, infoO, infoN,
103-
true);
104+
overwrite);
104105
}
105106

106107
/*----------------------------------------------------------------------------*/
@@ -157,7 +158,8 @@ XrdMgmOfs::symlink(const char* source_name,
157158
return SFS_ERROR;
158159
}
159160

160-
return _symlink(sourcen.c_str(), targetn.c_str(), error, vid, infoO, infoN);
161+
return _symlink(sourcen.c_str(), targetn.c_str(), error, vid, infoO, infoN,
162+
overwrite);
161163
}
162164

163165
/*----------------------------------------------------------------------------*/
@@ -167,7 +169,8 @@ XrdMgmOfs::_symlink(const char* source_name,
167169
XrdOucErrInfo& error,
168170
eos::common::VirtualIdentity& vid,
169171
const char* infoO,
170-
const char* infoN
172+
const char* infoN,
173+
bool overwrite
171174
)
172175
/*----------------------------------------------------------------------------*/
173176
/*
@@ -216,8 +219,12 @@ XrdMgmOfs::_symlink(const char* source_name,
216219
_exists(source_name, file_exists, error, vid, infoN);
217220

218221
if (file_exists != XrdSfsFileExistNo) {
219-
errno = EEXIST;
220-
return Emsg(epname, error, ENOENT, "symlink - source exists");
222+
if (overwrite) {
223+
_rem(source_name, error, vid, infoO);
224+
} else {
225+
errno = EEXIST;
226+
return Emsg(epname, error, ENOENT, "symlink - source exists");
227+
}
221228
}
222229

223230
{

mgm/proc/user/File.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,12 @@ ProcCommand::File()
629629
cmdok = true;
630630
XrdOucString source = pOpaque->Get("mgm.file.source");
631631
XrdOucString target = pOpaque->Get("mgm.file.target");
632+
XrdOucString forceS = pOpaque->Get("mgm.file.force");
633+
const char* cc = forceS.c_str();
634+
bool force = forceS == "1";
632635

633-
if (gOFS->symlink(source.c_str(), target.c_str(), *mError, *pVid, 0, 0, true)) {
636+
if (gOFS->symlink(source.c_str(), target.c_str(), *mError, *pVid, 0, 0,
637+
force)) {
634638
stdErr += "error: unable to link";
635639
retc = errno;
636640
} else {

0 commit comments

Comments
 (0)