/******************************************************************************/
/* */
/* X r d O s s U n l i n k . c c */
/* */
/* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD 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 Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see . */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdOss/XrdOssApi.hh"
#include "XrdOss/XrdOssCache.hh"
#include "XrdOss/XrdOssConfig.hh"
#include "XrdOss/XrdOssError.hh"
#include "XrdOss/XrdOssOpaque.hh"
#include "XrdOss/XrdOssPath.hh"
#include "XrdOss/XrdOssTrace.hh"
/******************************************************************************/
/* G l o b a l E r r o r R o u t i n g O b j e c t */
/******************************************************************************/
extern XrdSysError OssEroute;
extern XrdOucTrace OssTrace;
/******************************************************************************/
/* R e m d i r */
/******************************************************************************/
/*
Function: Delete a directory from the namespace.
Input: path - Is the fully qualified name of the dir to be removed.
envP - Environmental information.
Output: Returns XrdOssOK upon success and -errno upon failure.
*/
int XrdOssSys::Remdir(const char *path, int Opts, XrdOucEnv *eP)
{
unsigned long long opts;
int retc;
struct stat statbuff;
char local_path[MAXPATHLEN+1+8];
// Build the right local and remote paths.
//
if (Opts & XRDOSS_isPFN) strcpy(local_path, path);
else {retc = Check_RO(Unlink, opts, path, "remove");
if ( (retc = GenLocalPath( path, local_path))) return retc;
}
// Check if this path is really a directory
//
if (lstat(local_path, &statbuff)) return (errno == ENOENT ? 0 : -errno);
if ((statbuff.st_mode & S_IFMT) != S_IFDIR) return -ENOTDIR;
// Complete by calling Unlink()
//
return Unlink(path, Opts);
}
/******************************************************************************/
/* U n l i n k */
/******************************************************************************/
/*
Function: Delete a file from the namespace and release it's data storage.
Input: path - Is the fully qualified name of the file to be removed.
envP - Environmental information.
Output: Returns XrdOssOK upon success and -errno upon failure.
*/
int XrdOssSys::Unlink(const char *path, int Opts, XrdOucEnv *eP)
{
EPNAME("Unlink")
unsigned long long haslf, remotefs;
int i, retc2, doAdjust = 0, retc = XrdOssOK;
struct stat statbuff;
char *fnp;
char local_path[MAXPATHLEN+1+8];
char remote_path[MAXPATHLEN+1];
// Build the right local and remote paths.
//
if (Opts & XRDOSS_isPFN)
{strcpy(local_path, path),
*remote_path = '\0';
haslf = Opts & XRDOSS_isMIG;
remotefs = 0;
} else {
remotefs = Check_RO(Unlink, haslf, path, "remove");
if ( (retc = GenLocalPath( path, local_path))
|| (retc = GenRemotePath(path, remote_path)) ) return retc;
haslf &= XRDEXP_MAKELF;
}
// Check if this path is really a directory of a symbolic link elsewhere
//
if (lstat(local_path, &statbuff)) retc = (errno == ENOENT ? 0 : -errno);
else if ((statbuff.st_mode & S_IFMT) == S_IFLNK)
retc = BreakLink(local_path, statbuff);
else if ((statbuff.st_mode & S_IFMT) == S_IFDIR)
{i = strlen(local_path);
if (local_path[i-1] != '/') strcpy(local_path+i, "/");
if ((retc = rmdir(local_path))) retc = -errno;
DEBUG("dir rc=" <" <