Ejemplo n.º 1
0
void
tr_torrentRemoveResume (const tr_torrent * tor)
{
  char * filename = getResumeFilename (tor);
  tr_remove (filename);
  tr_free (filename);
}
Ejemplo n.º 2
0
static void
rm_rf (const char * killme)
{
  struct stat sb;

  if (!stat (killme, &sb))
    {
      DIR * odir;

      if (S_ISDIR (sb.st_mode) && ((odir = opendir (killme))))
        {
          struct dirent *d;
          for (d = readdir(odir); d != NULL; d=readdir(odir))
            {
              if (d->d_name && strcmp(d->d_name,".") && strcmp(d->d_name,".."))
                {
                  char * tmp = tr_buildPath (killme, d->d_name, NULL);
                  rm_rf (tmp);
                  tr_free (tmp);
                }
            }
          closedir (odir);
        }

      if (verbose)
        fprintf (stderr, "cleanup: removing %s\n", killme);

      tr_remove (killme);
    }
}
Ejemplo n.º 3
0
static void
create_text_file (const char * path, const char * contents)
{
  FILE * fp;
  char * dir;

  dir = tr_dirname (path);
  tr_mkdirp (dir, 0700);
  tr_free (dir);

  tr_remove (path);
  fp = fopen (path, "w+");
  fprintf (fp, "%s", contents);
  fclose (fp);

  sync ();
}
Ejemplo n.º 4
0
static void
onFileAdded (tr_session * session, const char * dir, const char * file)
{
    char * filename = tr_buildPath (dir, file, NULL);
    tr_ctor * ctor = tr_ctorNew (session);
    int err = tr_ctorSetMetainfoFromFile (ctor, filename);

    if (!err)
    {
        tr_torrentNew (ctor, &err, NULL);

        if (err == TR_PARSE_ERR)
            tr_logAddError ("Error parsing .torrent file \"%s\"", file);
        else
        {
            bool trash = false;
            int test = tr_ctorGetDeleteSource (ctor, &trash);

            tr_logAddInfo ("Parsing .torrent file successful \"%s\"", file);

            if (!test && trash)
            {
                tr_logAddInfo ("Deleting input .torrent file \"%s\"", file);
                if (tr_remove (filename))
                    tr_logAddError ("Error deleting .torrent file: %s", tr_strerror (errno));
            }
            else
            {
                char * new_filename = tr_strdup_printf ("%s.added", filename);
                tr_rename (filename, new_filename);
                tr_free (new_filename);
            }
        }
    }

    tr_ctorFree (ctor);
    tr_free (filename);
}
Ejemplo n.º 5
0
static void
blocklistDelete (tr_blocklistFile * b)
{
  blocklistClose (b);
  tr_remove (b->filename);
}
Ejemplo n.º 6
0
void tr_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
{
	if(level>=log_conf.level && log_conf.mode !=TO_NONE)
	{
		char buf[1024];
		char date[64];
		struct tm *tm;
		va_list vp;
		int num;
		time_t current_time=time(NULL);
		tm=localtime(&current_time);
		//snprintf(date,strlen(date)-1,"%d-%d %d:%d:%d",tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
		strftime(date,sizeof(date),"%b %e %T",tm);
		va_start(vp,fmt);
		vsnprintf(buf,sizeof(buf),fmt,vp);
		va_end(vp);
		if(log_conf.mode==TO_SCREEN || log_conf.mode==TO_BOTH)
		{
			fprintf(stderr,"\033[37;40m[%s] %s \033[37m%s()@%s:%d => \033[0;37;40m%s\n\033[0m",date,log_descriptions[level].color,function,file,line,buf);
			fflush(stderr);
		}
		if(log_conf.fp!=NULL)
		{
			num=fprintf(log_conf.fp,"[%s] %s %s()@%s:line %d  %s\n",date,log_descriptions[level].nocolor,function,file,line,buf);
			if(num>0)
			{
				fflush(log_conf.fp);
				log_conf.current+=num;
				if(log_conf.current>=log_conf.limit)
				{
					fclose(log_conf.fp);
					log_conf.fp=NULL;
					if(log_conf.rotate==1){
						int i;
						char old_name[FILE_PATH_LEN];
						char new_name[FILE_PATH_LEN];
						for(i=log_conf.backup;i>=1;i--)
						{
							snprintf(old_name,sizeof(old_name),"%s.bak.%d",log_conf.file_name,i);
							snprintf(new_name,sizeof(new_name),"%s.bak.%d",log_conf.file_name,i+1);
							if(tr_exist(old_name)==0){
								continue;
							}else{
								if(i==log_conf.backup){
									tr_remove(old_name);
									continue;
								}
								tr_rename(old_name,new_name);
							}
						}
						snprintf(new_name,sizeof(new_name),"%s.bak.1",log_conf.file_name);
						tr_rename(log_conf.file_name,new_name);
					}else{
						tr_remove(log_conf.file_name);
					}
					start_log();
				}
			}
		}
	}
}