Blame src/rmJob.cc

Packit 8f70b4
/*
Packit 8f70b4
 * lftp - file transfer program
Packit 8f70b4
 *
Packit 8f70b4
 * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
Packit 8f70b4
 *
Packit 8f70b4
 * This program is free software; you can redistribute it and/or modify
Packit 8f70b4
 * it under the terms of the GNU General Public License as published by
Packit 8f70b4
 * the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
 * (at your option) any later version.
Packit 8f70b4
 *
Packit 8f70b4
 * This program is distributed in the hope that it will be useful,
Packit 8f70b4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
 * GNU General Public License for more details.
Packit 8f70b4
 *
Packit 8f70b4
 * You should have received a copy of the GNU General Public License
Packit 8f70b4
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8f70b4
 */
Packit 8f70b4
Packit 8f70b4
#include <config.h>
Packit 8f70b4
Packit 8f70b4
#include <errno.h>
Packit 8f70b4
#include "rmJob.h"
Packit 8f70b4
#include "plural.h"
Packit 8f70b4
#include "url.h"
Packit 8f70b4
#include "misc.h"
Packit 8f70b4
Packit 8f70b4
rmJob::rmJob(FileAccess *s,ArgV *a) : TreatFileJob(s,a)
Packit 8f70b4
{
Packit 8f70b4
   mode=FA::REMOVE;
Packit 8f70b4
   recurse=false;
Packit 8f70b4
   depth_first=true;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
void rmJob::Recurse()
Packit 8f70b4
{
Packit 8f70b4
   set_maxdepth(-1);
Packit 8f70b4
   Need(FileInfo::TYPE);
Packit 8f70b4
   recurse=true;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
void  rmJob::SayFinal()
Packit 8f70b4
{
Packit 8f70b4
   if(failed==file_count)
Packit 8f70b4
      return;
Packit 8f70b4
   if(file_count==1)
Packit 8f70b4
      printf(_("%s ok, `%s' removed\n"),op,first->name.get());
Packit 8f70b4
   else if(failed)
Packit 8f70b4
   {
Packit 8f70b4
      if(mode==FA::REMOVE_DIR)
Packit 8f70b4
	 printf(plural("%s failed for %d of %d director$y|ies$\n",file_count),
Packit 8f70b4
	    op,failed,file_count);
Packit 8f70b4
      else
Packit 8f70b4
	 printf(plural("%s failed for %d of %d file$|s$\n",file_count),
Packit 8f70b4
	    op,failed,file_count);
Packit 8f70b4
   }
Packit 8f70b4
   else
Packit 8f70b4
   {
Packit 8f70b4
      if(mode==FA::REMOVE_DIR)
Packit 8f70b4
	 printf(plural("%s ok, %d director$y|ies$ removed\n",file_count),
Packit 8f70b4
	    op,file_count);
Packit 8f70b4
      else
Packit 8f70b4
	 printf(plural("%s ok, %d file$|s$ removed\n",file_count),
Packit 8f70b4
	    op,file_count);
Packit 8f70b4
   }
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
void rmJob::TreatCurrent(const char *d, const FileInfo *fi)
Packit 8f70b4
{
Packit 8f70b4
   /* If we're recursing and this is a directory, rmdir it.  (If we're
Packit 8f70b4
    * not recursing, just send an rm and let it fail.) */
Packit 8f70b4
   if(recurse && (fi->defined&fi->TYPE) && (fi->filetype==fi->DIRECTORY))
Packit 8f70b4
      session->Open(fi->name,FA::REMOVE_DIR);
Packit 8f70b4
   else
Packit 8f70b4
      session->Open(fi->name,mode);
Packit 8f70b4
}