Exemplo n.º 1
0
/**
 * If requested strip leading components of the path so that we can
 * save file as if it came from a subdirectory.  This is most useful
 * for dealing with snapshots, by removing the snapshot directory, or
 * in handling vendor migrations where files have been restored with
 * a vendor product into a subdirectory.
 */
void strip_path(FF_PKT *ff_pkt)
{
   if (!bit_is_set(FO_STRIPPATH, ff_pkt->flags) || ff_pkt->strip_path <= 0) {
      Dmsg1(200, "No strip for %s\n", ff_pkt->fname);
      return;
   }

   if (!ff_pkt->fname_save) {
     ff_pkt->fname_save = get_pool_memory(PM_FNAME);
     ff_pkt->link_save = get_pool_memory(PM_FNAME);
   }

   pm_strcpy(ff_pkt->fname_save, ff_pkt->fname);
   if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
      pm_strcpy(ff_pkt->link_save, ff_pkt->link);
      Dmsg2(500, "strcpy link_save=%d link=%d\n", strlen(ff_pkt->link_save),
         strlen(ff_pkt->link));
      Dsm_check(200);
   }

   /**
    * Strip path. If it doesn't succeed put it back. If it does, and there
    * is a different link string, attempt to strip the link. If it fails,
    * back them both back. Do not strip symlinks. I.e. if either stripping
    * fails don't strip anything.
    */
   if (!do_strip(ff_pkt->strip_path, ff_pkt->fname)) {
      unstrip_path(ff_pkt);
      goto rtn;
   }

   /**
    * Strip links but not symlinks
    */
   if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
      if (!do_strip(ff_pkt->strip_path, ff_pkt->link)) {
         unstrip_path(ff_pkt);
      }
   }

rtn:
   Dmsg3(100, "fname=%s stripped=%s link=%s\n", ff_pkt->fname_save, ff_pkt->fname, ff_pkt->link);
}
Exemplo n.º 2
0
inline
bool config_split_impl(io::Spanned<ZS> line, io::Spanned<XString> *key, io::Spanned<ZS> *value)
{
    // unconditionally fail if line contains control characters
    if (std::find_if(line.data.begin(), line.data.end(),
                [](unsigned char c) { return c < ' '; }
                ) != line.data.end())
        return false;

    if (!do_split(line, key, value))
        return false;
    *key = do_strip(*key);
    *value = do_lstrip(*value);
    return true;
}
Exemplo n.º 3
0
 std::string rstrip( const std::string & str, const std::string & chars )
 {
     return do_strip( str, RIGHTSTRIP, chars );
 }
Exemplo n.º 4
0
 std::string lstrip( const std::string & str, const std::string & chars )
 {
     return do_strip( str, LEFTSTRIP, chars );
 }
Exemplo n.º 5
0
 std::string strip( const std::string & str, const std::string & chars )
 {
     return do_strip( str, BOTHSTRIP, chars );
 }
Exemplo n.º 6
0
static PyObject *
strop_rstrip(PyObject *self, PyObject *args)
{
	WARN;
	return do_strip(args, RIGHTSTRIP);
}
Exemplo n.º 7
0
static PyObject *
strop_lstrip(PyObject *self, PyObject *args)
{
	WARN;
	return do_strip(args, LEFTSTRIP);
}
Exemplo n.º 8
0
static PyObject *
strop_strip(PyObject *self, PyObject *args)
{
	WARN;
	return do_strip(args, BOTHSTRIP);
}