Exemplo n.º 1
0
/* create devices for mapped drives */
static void create_drive_devices(void)
{
    char *path, *p, *link, *device;
    struct dos_drive *drive;
    unsigned int i;
    HKEY drives_key;
    enum device_type drive_type;
    WCHAR driveW[] = {'a',':',0};

    if (!(path = get_dosdevices_path( &p ))) return;
    if (RegOpenKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &drives_key )) drives_key = 0;

    for (i = 0; i < MAX_DOS_DRIVES; i++)
    {
        p[0] = 'a' + i;
        p[2] = 0;
        if (!(link = read_symlink( path ))) continue;
        p[2] = ':';
        device = read_symlink( path );

        drive_type = i < 2 ? DEVICE_FLOPPY : DEVICE_HARDDISK_VOL;
        if (drives_key)
        {
            WCHAR buffer[32];
            DWORD j, type, size = sizeof(buffer);

            driveW[0] = 'a' + i;
            if (!RegQueryValueExW( drives_key, driveW, NULL, &type, (BYTE *)buffer, &size ) &&
                type == REG_SZ)
            {
                for (j = 0; j < sizeof(drive_types)/sizeof(drive_types[0]); j++)
                    if (drive_types[j][0] && !strcmpiW( buffer, drive_types[j] ))
                    {
                        drive_type = j;
                        break;
                    }
                if (drive_type == DEVICE_FLOPPY && i >= 2) drive_type = DEVICE_HARDDISK;
            }
        }

        if (!create_disk_device( NULL, drive_type, &drive ))
        {
            drive->unix_mount = link;
            drive->unix_device = device;
            set_drive_letter( drive, i );
        }
        else
        {
            RtlFreeHeap( GetProcessHeap(), 0, link );
            RtlFreeHeap( GetProcessHeap(), 0, device );
        }
    }
    RegCloseKey( drives_key );
    RtlFreeHeap( GetProcessHeap(), 0, path );
}
Exemplo n.º 2
0
ssize_t get_self_executable_path(char *buf, size_t len)
{
#if defined(linux)
  return read_symlink("/proc/self/exe", buf, len);
#elif defined (__sun__)
  return read_symlink("/proc/self/path/a.out", buf, len);
#elif defined (__APPLE__)
  uint32_t bufsize = len;
  return _NSGetExecutablePath(buf, &bufsize) == -1 && len ? -1 : bufsize;
#else
#error Unable to find executable path
#endif
}
Exemplo n.º 3
0
void ObjectLibrary::processFolder(const char* filepath)
{
	// Create object library
	path library_path(filepath);
	if(is_directory(library_path))
	{
		recursive_directory_iterator iter(library_path);
		recursive_directory_iterator end;
		while(iter != end)
		{
			if(is_directory(iter->path()))
			{
				object_idx.push_back(images.size());
				object_names.push_back(iter->path().filename().generic_string());
				//std::cout << "Object: " <<  object_names.back() << " " << object_idx.back() << std::endl;

				// Handle Symlink Directories
				if(is_symlink(iter->path()))
				{
					iter = recursive_directory_iterator(canonical(read_symlink(iter->path()), library_path));
				}
			}
			else
			{
				// Initialize object feature
				Mat img_object = imread(iter->path().generic_string(), CV_LOAD_IMAGE_COLOR);
				if( !img_object.data )
				{ 
					throw std::runtime_error("Error Reading Image"); 
				}
				ImageData img = processImage(img_object);
				img.name = iter->path().stem().generic_string();
				//std::cout << "Object: " << object_names.back() << " Image: " << img.name << std::endl;

				if(img.name == object_names.back())
				{
					object_img_idx.push_back(images.size());
					//std::cout << object_names.back() << " " << images.size() << std::endl;
				}

				//-- Step 3: Add to object library
				images.push_back(std::move(img));
			}
			++iter;
		}
	}
	//std::cout << "Num Objects: " << object_idx.size() << std::endl;
}
void FileDataProvider::updateInotifyWatch() {
  /**
   * Initiailze inotify and get the file descriptor we will use to watch for
   * changes.
   */
  auto inotifyFD = inotify_init();
  if (inotifyFD < 0) {
    throw std::runtime_error(folly::format(
        "Failed to initialize inotify for '{}'. Errno: '{}'",
        filePath_.data(), errno).str());
  }
  folly::File tmpInotify(inotifyFD, /* ownsFd */ true);

  /**
   * Right now mcrouter configs are a symlink to the actual config file.
   * We need to watch both the link and the config file for changes. Just
   * to be safe, write the code to handle chained symlinks.
   */

  path link(filePath_);
  while (true) {
    // Add a watch on the current link or file
    int wd = inotify_add_watch(inotifyFD, link.string().data(), INOTIFY_MASK);
    if (wd < 0) {
      throw std::runtime_error(
        folly::format(
          "Can not add inotify watch for '{}'", link.string().data()).str());
    }
    // Read the link (if it is one)
    boost::system::error_code ec;
    auto file = read_symlink(link, ec);
    if (file.empty()) {
      break;
    }
    // We read a link
    file = complete(file, link.parent_path());
    std::swap(link, file);
  }
  inotify_ = std::move(tmpInotify);
}
Exemplo n.º 5
0
std::string self_exec_filename() {
	// nice overview of crossplatform methods:
	// http://stackoverflow.com/questions/5919996

	#ifdef __linux
	return read_symlink("/proc/self/exe");
	#elif __APPLE__
	uint32_t bufsize = 1024;

	while (true) {
		std::unique_ptr<char[]> buf{new char[bufsize]};

		if (_NSGetExecutablePath(buf.get(), &bufsize) < 0) {
			continue;
		}

		return std::string{buf.get()};
	}
	#elif WIN32
	static_assert(false, "subprocess::self_filename is not yet implemented for WIN32");
	#else
	static_assert(false, "subprocess::self_filename is not yet implemented for... whatever platform you're using right now.");
	#endif
}
Exemplo n.º 6
0
path executable_path() {
  return read_symlink("/proc/self/exe");
}
Exemplo n.º 7
0
/* Returns a NodeInfo struct for the given node */
const struct NodeInfo *
get_node_info( GNode *node )
{
	static struct NodeInfo ninfo = {
		NULL,	/* name */
		NULL,	/* prefix */
		NULL,	/* size */
		NULL,	/* size_abbr */
		NULL,	/* size_alloc */
		NULL,	/* size_alloc_abbr */
		NULL,	/* user_name */
		NULL,	/* group_name */
		NULL,	/* atime */
		NULL,	/* mtime */
		NULL,	/* ctime */
		NULL,	/* subtree_size */
		NULL,	/* subtree_size_abbr */
		NULL,	/* file_type_desc */
		NULL,	/* target */
		NULL	/* abstarget */
	};
	struct passwd *pw;
	struct group *gr;
	static char blank[] = "-";
	const char *absname;
	const char *cstr;
	char *str;

	absname = node_absname( node );

	/* Name */
	if (strlen( NODE_DESC(node)->name ) > 0)
		cstr = NODE_DESC(node)->name;
	else
		cstr = _("/. (root)");
	ninfo.name = xstrredup( ninfo.name, cstr );
	/* Prefix */
	str = g_dirname( absname );
	if (!strcmp( str, "/" )) {
		g_free( str );
		str = g_strdup( _("/. (root)") );
	}
	ninfo.prefix = xstrredup( ninfo.prefix, str );
	g_free( str );

	/* Size */
	ninfo.size = xstrredup( ninfo.size, i64toa( NODE_DESC(node)->size ) );
	ninfo.size_abbr = xstrredup( ninfo.size_abbr, abbrev_size( NODE_DESC(node)->size ) );
	/* Allocation size */
	ninfo.size_alloc = xstrredup( ninfo.size_alloc, i64toa( NODE_DESC(node)->size_alloc ) );
	ninfo.size_alloc_abbr = xstrredup( ninfo.size_alloc_abbr, abbrev_size( NODE_DESC(node)->size_alloc ) );

	/* User name */
	pw = getpwuid( NODE_DESC(node)->user_id );
	if (pw == NULL)
		cstr = _("Unknown");
	else
		cstr = pw->pw_name;
	ninfo.user_name = xstrredup( ninfo.user_name, cstr );
	/* Group name */
	gr = getgrgid( NODE_DESC(node)->group_id );
	if (gr == NULL)
		cstr = _("Unknown");
	else
		cstr = gr->gr_name;
	ninfo.group_name = xstrredup( ninfo.group_name, cstr );

	/* Timestamps - remember to strip ctime's trailing newlines */
	ninfo.atime = xstrredup( ninfo.atime, ctime( &NODE_DESC(node)->atime ) );
        ninfo.atime[strlen( ninfo.atime ) - 1] = '\0';
	ninfo.mtime = xstrredup( ninfo.mtime, ctime( &NODE_DESC(node)->mtime ) );
        ninfo.mtime[strlen( ninfo.mtime ) - 1] = '\0';
	ninfo.ctime = xstrredup( ninfo.ctime, ctime( &NODE_DESC(node)->ctime ) );
	ninfo.ctime[strlen( ninfo.ctime ) - 1] = '\0';

	/* For directories: subtree size */
	if (NODE_DESC(node)->type == NODE_DIRECTORY) {
		ninfo.subtree_size = xstrredup( ninfo.subtree_size, i64toa( DIR_NODE_DESC(node)->subtree.size ) );
		ninfo.subtree_size_abbr = xstrredup( ninfo.subtree_size_abbr, abbrev_size( DIR_NODE_DESC(node)->subtree.size ) );
	}
	else {
		ninfo.subtree_size = xstrredup( ninfo.subtree_size, blank );
		ninfo.subtree_size_abbr = xstrredup( ninfo.subtree_size_abbr, blank );
	}

	/* For regular files: file type description */
	if (NODE_DESC(node)->type == NODE_REGFILE)
		ninfo.file_type_desc = get_file_type_desc( absname );
	else
		ninfo.file_type_desc = blank;

	/* For symbolic links: target name(s) */
	if (NODE_DESC(node)->type == NODE_SYMLINK) {
		ninfo.target = read_symlink( absname );
		str = g_dirname( absname );
		ninfo.abstarget = absname_merge( str, ninfo.target );
		g_free( str );
	}
	else {
		ninfo.target = blank;
		ninfo.abstarget = blank;
	}

	return &ninfo;
}
Exemplo n.º 8
0
int
putDirUtil( rcComm_t **myConn, char *srcDir, char *targColl,
            rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp,
            bulkOprInp_t *bulkOprInp, rodsRestart_t *rodsRestart,
            bulkOprInfo_t *bulkOprInfo ) {
    char srcChildPath[MAX_NAME_LEN], targChildPath[MAX_NAME_LEN];

    if ( srcDir == NULL || targColl == NULL ) {
        rodsLog( LOG_ERROR,
                 "putDirUtil: NULL srcDir or targColl input" );
        return USER__NULL_INPUT_ERR;
    }

    if ( isPathSymlink( rodsArgs, srcDir ) > 0 ) {
        return 0;
    }

    if ( rodsArgs->recursive != True ) {
        rodsLog( LOG_ERROR,
                 "putDirUtil: -r option must be used for putting %s directory",
                 srcDir );
        return USER_INPUT_OPTION_ERR;
    }

    if ( rodsArgs->redirectConn == True && rodsArgs->force != True ) {
        int reconnFlag;
        if ( rodsArgs->reconnect == True ) {
            reconnFlag = RECONN_TIMEOUT;
        }
        else {
            reconnFlag = NO_RECONN;
        }
        /* reconnect to the resource server */
        rstrcpy( dataObjOprInp->objPath, targColl, MAX_NAME_LEN );
        redirectConnToRescSvr( myConn, dataObjOprInp, myRodsEnv, reconnFlag );
        rodsArgs->redirectConn = 0;    /* only do it once */
    }

    rcComm_t *conn = *myConn;
    boost::filesystem::path srcDirPath( srcDir );
    if ( !exists( srcDirPath ) || !is_directory( srcDirPath ) ) {
        rodsLog( LOG_ERROR,
                 "putDirUtil: opendir local dir error for %s, errno = %d\n",
                 srcDir, errno );
        return USER_INPUT_PATH_ERR;
    }

    if ( rodsArgs->verbose == True ) {
        fprintf( stdout, "C- %s:\n", targColl );
    }

    int bulkFlag = NON_BULK_OPR;
    if ( bulkOprInfo != NULL ) {
        bulkFlag = bulkOprInfo->flags;
    }

    int savedStatus = 0;
    boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
    for ( boost::filesystem::directory_iterator itr( srcDirPath ); itr != end_itr; ++itr ) {
        boost::filesystem::path p = itr->path();
        snprintf( srcChildPath, MAX_NAME_LEN, "%s",
                  p.c_str() );

        if ( isPathSymlink( rodsArgs, srcChildPath ) > 0 ) {
            continue;
        }
        if ( !exists( p ) ) {
            rodsLog( LOG_ERROR,
                     "putDirUtil: stat error for %s, errno = %d\n",
                     srcChildPath, errno );
            return USER_INPUT_PATH_ERR;
        }

        if ( is_symlink( p ) ) {
            boost::filesystem::path cp = read_symlink( p );
            snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s",
                      srcDir, cp.c_str() );
            p = boost::filesystem::path( srcChildPath );
        }
        rodsLong_t dataSize = 0;
        dataObjOprInp->createMode = getPathStMode( p.c_str() );
        objType_t childObjType;
        if ( is_regular_file( p ) ) {
            childObjType = DATA_OBJ_T;
            dataSize = file_size( p );
        }
        else if ( is_directory( p ) ) {
            childObjType = COLL_OBJ_T;
        }
        else {
            rodsLog( LOG_ERROR,
                     "putDirUtil: unknown local path type for %s",
                     srcChildPath );
            savedStatus = USER_INPUT_PATH_ERR;
            continue;
        }
        boost::filesystem::path childPath = p.filename();
        snprintf( targChildPath, MAX_NAME_LEN, "%s/%s",
                  targColl, childPath.c_str() );
        if ( childObjType == DATA_OBJ_T ) {
            if ( bulkFlag == BULK_OPR_SMALL_FILES &&
                    file_size( p ) > MAX_BULK_OPR_FILE_SIZE ) {
                continue;
            }
            else if ( bulkFlag == BULK_OPR_LARGE_FILES &&
                      file_size( p ) <= MAX_BULK_OPR_FILE_SIZE ) {
                continue;
            }
        }

        int status = chkStateForResume( conn, rodsRestart, targChildPath,
                                        rodsArgs, childObjType, &dataObjOprInp->condInput, 1 );

        if ( status < 0 ) {
            /* restart failed */
            return status;
        }
        else if ( status == 0 ) {
            if ( bulkFlag == BULK_OPR_SMALL_FILES &&
                    ( rodsRestart->restartState & LAST_PATH_MATCHED ) != 0 ) {
                /* enable foreFlag one time */
                setForceFlagForRestart( bulkOprInp, bulkOprInfo );
            }
            continue;
        }

        if ( childObjType == DATA_OBJ_T ) {   /* a file */
            if ( bulkFlag == BULK_OPR_SMALL_FILES ) {
                status = bulkPutFileUtil( conn, srcChildPath, targChildPath,
                                          dataSize,  dataObjOprInp->createMode, rodsArgs,
                                          bulkOprInp, bulkOprInfo );
            }
            else {
                /* normal put */
                status = putFileUtil( conn, srcChildPath, targChildPath,
                                      dataSize, rodsArgs, dataObjOprInp );
            }
            if ( rodsRestart->fd > 0 ) {
                if ( status >= 0 ) {
                    if ( bulkFlag == BULK_OPR_SMALL_FILES ) {
                        if ( status > 0 ) {
                            /* status is the number of files bulk loaded */
                            rodsRestart->curCnt += status;
                            status = writeRestartFile( rodsRestart,
                                                       targChildPath );
                        }
                    }
                    else {
                        /* write the restart file */
                        rodsRestart->curCnt ++;
                        status = writeRestartFile( rodsRestart, targChildPath );
                    }
                }
            }
        }
        else {        /* a directory */
            status = mkColl( conn, targChildPath );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "putDirUtil: mkColl error for %s", targChildPath );
            }
            status = putDirUtil( myConn, srcChildPath, targChildPath,
                                 myRodsEnv, rodsArgs, dataObjOprInp, bulkOprInp,
                                 rodsRestart, bulkOprInfo );

        }

        if ( status < 0 &&
                status != CAT_NO_ROWS_FOUND ) {
            rodsLogError( LOG_ERROR, status,
                          "putDirUtil: put %s failed. status = %d",
                          srcChildPath, status );
            savedStatus = status;
            if ( rodsRestart->fd > 0 ) {
                break;
            }
        }
    }
    return savedStatus;
}
Exemplo n.º 9
0
static int
fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf)
{
	char *pmode;	/* printable mode */
	const char *type = "unknown";
	awk_value_t tmp;
	static struct ftype_map {
		unsigned int mask;
		const char *type;
	} ftype_map[] = {
		{ S_IFREG, "file" },
		{ S_IFBLK, "blockdev" },
		{ S_IFCHR, "chardev" },
		{ S_IFDIR, "directory" },
#ifdef S_IFSOCK
		{ S_IFSOCK, "socket" },
#endif
#ifdef S_IFIFO
		{ S_IFIFO, "fifo" },
#endif
#ifdef S_IFLNK
		{ S_IFLNK, "symlink" },
#endif
#ifdef S_IFDOOR	/* Solaris weirdness */
		{ S_IFDOOR, "door" },
#endif /* S_IFDOOR */
	};
	int j, k;

	/* empty out the array */
	clear_array(array);

	/* fill in the array */
	array_set(array, "name", make_const_string(name, strlen(name), & tmp));
	array_set_numeric(array, "dev", sbuf->st_dev);
	array_set_numeric(array, "ino", sbuf->st_ino);
	array_set_numeric(array, "mode", sbuf->st_mode);
	array_set_numeric(array, "nlink", sbuf->st_nlink);
	array_set_numeric(array, "uid", sbuf->st_uid);
	array_set_numeric(array, "gid", sbuf->st_gid);
	array_set_numeric(array, "size", sbuf->st_size);
	array_set_numeric(array, "blocks", sbuf->st_blocks);
	array_set_numeric(array, "atime", sbuf->st_atime);
	array_set_numeric(array, "mtime", sbuf->st_mtime);
	array_set_numeric(array, "ctime", sbuf->st_ctime);

	/* for block and character devices, add rdev, major and minor numbers */
	if (S_ISBLK(sbuf->st_mode) || S_ISCHR(sbuf->st_mode)) {
		array_set_numeric(array, "rdev", sbuf->st_rdev);
		array_set_numeric(array, "major", major(sbuf->st_rdev));
		array_set_numeric(array, "minor", minor(sbuf->st_rdev));
	}

#ifdef HAVE_ST_BLKSIZE
	array_set_numeric(array, "blksize", sbuf->st_blksize);
#endif /* HAVE_ST_BLKSIZE */

	pmode = format_mode(sbuf->st_mode);
	array_set(array, "pmode", make_const_string(pmode, strlen(pmode), & tmp));

	/* for symbolic links, add a linkval field */
	if (S_ISLNK(sbuf->st_mode)) {
		char *buf;
		ssize_t linksize;

		if ((buf = read_symlink(name, sbuf->st_size,
					& linksize)) != NULL)
			array_set(array, "linkval", make_malloced_string(buf, linksize, & tmp));
		else
			warning(ext_id, "stat: unable to read symbolic link `%s'", name);
	}

	/* add a type field */
	type = "unknown";	/* shouldn't happen */
	for (j = 0, k = sizeof(ftype_map)/sizeof(ftype_map[0]); j < k; j++) {
		if ((sbuf->st_mode & S_IFMT) == ftype_map[j].mask) {
			type = ftype_map[j].type;
			break;
		}
	}

	array_set(array, "type", make_const_string(type, strlen(type), &tmp));

	return 0;
}
Exemplo n.º 10
0
int
rsyncDirToCollUtil (rcComm_t *conn, rodsPath_t *srcPath, 
rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjInp_t *dataObjOprInp)
{
    int status = 0;
    int savedStatus = 0;
#ifndef USE_BOOST_FS
    DIR *dirPtr;
    struct dirent *myDirent;
#ifndef windows_platform
    struct stat statbuf;
#else
	struct irodsntstat statbuf;
#endif
#endif	/* #ifndef USE_BOOST_FS */
    char *srcDir, *targColl;
    rodsPath_t mySrcPath, myTargPath;

    if (srcPath == NULL || targPath == NULL) {
       rodsLog (LOG_ERROR,
          "rsyncDirToCollUtil: NULL srcPath or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    srcDir = srcPath->outPath;
    targColl = targPath->outPath;

    if (isPathSymlink (rodsArgs, srcDir) > 0) return 0;

    if (rodsArgs->recursive != True) {
        rodsLog (LOG_ERROR,
        "rsyncDirToCollUtil: -r option must be used for putting %s directory",
         srcDir);
        return (USER_INPUT_OPTION_ERR);
    }

#ifdef USE_BOOST_FS
    path srcDirPath (srcDir);
    if (!exists(srcDirPath) || !is_directory(srcDirPath)) {
#else
    dirPtr = opendir (srcDir);
    if (dirPtr == NULL) {
#endif  /* USE_BOOST_FS */
        rodsLog (LOG_ERROR,
        "rsyncDirToCollUtil: opendir local dir error for %s, errno = %d\n",
         srcDir, errno);
        return (USER_INPUT_PATH_ERR);
    }

    if (rodsArgs->verbose == True) {
        fprintf (stdout, "C- %s:\n", targColl);
    }

    memset (&mySrcPath, 0, sizeof (mySrcPath));
    memset (&myTargPath, 0, sizeof (myTargPath));
    myTargPath.objType = DATA_OBJ_T;
    mySrcPath.objType = LOCAL_FILE_T;

#ifdef USE_BOOST_FS
    directory_iterator end_itr; // default construction yields past-the-end
    for (directory_iterator itr(srcDirPath); itr != end_itr;++itr) {
        path p = itr->path();
        snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s",
          p.c_str ());
#else
    while ((myDirent = readdir (dirPtr)) != NULL) {
        if (strcmp (myDirent->d_name, ".") == 0 ||
          strcmp (myDirent->d_name, "..") == 0) {
            continue;
        }
        snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s/%s",
          srcDir, myDirent->d_name);
#endif	/* USE_BOOST_FS */

        if (isPathSymlink (rodsArgs, mySrcPath.outPath) > 0) continue;
#ifdef USE_BOOST_FS
#if 0
        path p (mySrcPath.outPath);
#endif
	if (!exists(p)) {
#else
#ifndef windows_platform
        status = stat (mySrcPath.outPath, &statbuf);
#else
	status = iRODSNt_stat(mySrcPath.outPath, &statbuf);
#endif

        if (status != 0) {
            closedir (dirPtr);
#endif  /* USE_BOOST_FS */
            rodsLog (LOG_ERROR,
              "rsyncDirToCollUtil: stat error for %s, errno = %d\n",
              mySrcPath.outPath, errno);
            return (USER_INPUT_PATH_ERR);
        }
#ifndef USE_BOOST_FS
        if ((statbuf.st_mode & S_IFREG) != 0 && rodsArgs->age == True) {
            if (ageExceeded (rodsArgs->agevalue, statbuf.st_mtime,
              rodsArgs->verbose, mySrcPath.outPath, statbuf.st_size)) 
                continue;
        }
#endif /* #ifndef USE_BOOST_FS */
#ifdef FILESYSTEM_META
        getFileMetaFromPath(mySrcPath.outPath, &dataObjOprInp->condInput);
#endif
	bzero (&myTargPath, sizeof (myTargPath));
#ifdef USE_BOOST_FS
        path childPath = p.filename();
        snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s",
          targColl, childPath.c_str());
        if (is_symlink (p)) {
            path cp = read_symlink (p);
            snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s/%s",
              srcDir, cp.c_str ());
            p = path (mySrcPath.outPath);
        }
	dataObjOprInp->createMode = getPathStMode (p);
	if (is_regular_file(p)) {
#else
        snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s",
          targColl, myDirent->d_name);
	dataObjOprInp->createMode = statbuf.st_mode;
        if ((statbuf.st_mode & S_IFREG) != 0) {     /* a file */
#endif
            myTargPath.objType = DATA_OBJ_T;
            mySrcPath.objType = LOCAL_FILE_T;
	    mySrcPath.objState = EXIST_ST;
#ifdef USE_BOOST_FS
	    mySrcPath.size = file_size (p);
#else
	    mySrcPath.size = statbuf.st_size;
#endif
	    getRodsObjType (conn, &myTargPath);
            status = rsyncFileToDataUtil (conn, &mySrcPath, &myTargPath,
              myRodsEnv, rodsArgs, dataObjOprInp);
	    /* fix a big mem leak */
            if (myTargPath.rodsObjStat != NULL) {
                freeRodsObjStat (myTargPath.rodsObjStat);
                myTargPath.rodsObjStat = NULL;
            }
#if 0
	    if (myTargPath.objState != NOT_EXIST_ST)
	        freeRodsObjStat (myTargPath.rodsObjStat);
#endif
#ifdef USE_BOOST_FS
	} else if (is_directory(p)) {
#else
        } else if ((statbuf.st_mode & S_IFDIR) != 0) {      /* a directory */
#endif
            status = 0;
            /* only do the sync if no -l option specified */
            if ( rodsArgs->longOption != True ) {
#ifdef FILESYSTEM_META
                status = mkCollRWithDirMeta (conn, targColl,
                                             myTargPath.outPath, mySrcPath.outPath);
#else
            	status = mkCollR (conn, targColl, myTargPath.outPath);
#endif
            }
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                  "rsyncDirToCollUtil: mkCollR error for %s", 
		  myTargPath.outPath);
            } else {
                myTargPath.objType = COLL_OBJ_T;
                mySrcPath.objType = LOCAL_DIR_T;
                mySrcPath.objState = myTargPath.objState = EXIST_ST;
                getRodsObjType (conn, &myTargPath);
                status = rsyncDirToCollUtil (conn, &mySrcPath, &myTargPath,
                  myRodsEnv, rodsArgs, dataObjOprInp);
	        /* fix a big mem leak */
                if (myTargPath.rodsObjStat != NULL) {
                    freeRodsObjStat (myTargPath.rodsObjStat);
                    myTargPath.rodsObjStat = NULL;
                }
#if 0
	        if (myTargPath.objState != NOT_EXIST_ST)
		    freeRodsObjStat (myTargPath.rodsObjStat);
#endif
            }
        } else {
            rodsLog (LOG_ERROR,
#ifdef USE_BOOST_FS
              "rsyncDirToCollUtil: unknown local path %s",
              mySrcPath.outPath);
#else
              "rsyncDirToCollUtil: unknown local path type %d for %s",
              statbuf.st_mode, mySrcPath.outPath);
#endif	/* USE_BOOST_FS */
            status = USER_INPUT_PATH_ERR;
        }

        if (status < 0) {
            savedStatus = status;
            rodsLogError (LOG_ERROR, status,
             "rsyncDirToCollUtil: put %s failed. status = %d",
              mySrcPath.outPath, status);
        }
    }
#ifndef USE_BOOST_FS
    closedir (dirPtr);
#endif

    if (savedStatus < 0) {
        return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND || 
      status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
        return (0);
    } else {
        return (status);
    }

}

int
rsyncCollToCollUtil (rcComm_t *conn, rodsPath_t *srcPath, 
rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjCopyInp_t *dataObjCopyInp)
{
    int status = 0;
    int savedStatus = 0;
    char *srcColl, *targColl;
    char targChildPath[MAX_NAME_LEN];
#if 0
    int collLen;
#else
    char parPath[MAX_NAME_LEN], childPath[MAX_NAME_LEN];
#endif
    rodsPath_t mySrcPath, myTargPath;
    collHandle_t collHandle;
    collEnt_t collEnt;
    dataObjCopyInp_t childDataObjCopyInp;

    dataObjInp_t *dataObjOprInp = &collHandle.dataObjInp;

    if (srcPath == NULL || targPath == NULL) {
       rodsLog (LOG_ERROR,
          "rsyncCollToCollUtil: NULL srcPath or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    srcColl = srcPath->outPath;
    targColl = targPath->outPath;

    if (rodsArgs->recursive != True) {
        rodsLog (LOG_ERROR,
        "rsyncCollToCollUtil: -r option must be used for collection %s",
         targColl);
        return (USER_INPUT_OPTION_ERR);
    }

#if 0
    status = rclOpenCollection (conn, srcColl,
      RECUR_QUERY_FG | VERY_LONG_METADATA_FG, &collHandle);
#else
    status = rclOpenCollection (conn, srcColl,
      VERY_LONG_METADATA_FG, &collHandle);
#endif

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "getCollUtil: rclOpenCollection of %s error. status = %d",
          srcColl, status);
        return status;
    }

    if (dataObjOprInp->specColl != NULL) {
        if (rodsArgs->verbose == True) {
            if (rodsArgs->verbose == True) {
                char objType[NAME_LEN];
                status = getSpecCollTypeStr (dataObjOprInp->specColl, objType);
                if (status < 0) 
                    fprintf (stdout, "C- %s    :\n", targColl);
		else
                    fprintf (stdout, "C- %s    %-5.5s :\n", targColl, objType);
            }
        }
    }

    memset (&mySrcPath, 0, sizeof (mySrcPath));
    memset (&myTargPath, 0, sizeof (myTargPath));
    myTargPath.objType = DATA_OBJ_T;
    mySrcPath.objType = DATA_OBJ_T;

#if 0
    collLen = strlen (srcColl);
    collLen = getOpenedCollLen (&collHandle);
#endif
    while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) {
        if (collEnt.objType == DATA_OBJ_T) {
            if (rodsArgs->age == True) {
                if (ageExceeded (rodsArgs->agevalue,
                  atoi (collEnt.modifyTime), rodsArgs->verbose,
                  collEnt.dataName, collEnt.dataSize)) continue;
            }
#if 0
            snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s%s/%s",
              targColl, collEnt.collName + collLen,
              collEnt.dataName);
#else
            snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s",
              targColl, collEnt.dataName);
#endif
            snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s/%s",
              collEnt.collName, collEnt.dataName);
            /* fill in some info for mySrcPath */
            if (strlen (mySrcPath.dataId) == 0)
                rstrcpy (mySrcPath.dataId, collEnt.dataId, NAME_LEN);
            mySrcPath.size = collEnt.dataSize;
            rstrcpy (mySrcPath.chksum, collEnt.chksum, CHKSUM_LEN);
            mySrcPath.objState = EXIST_ST;

#if 0
            getFileType (&myTargPath);
#else
	    getRodsObjType (conn, &myTargPath);
#endif

            status = rsyncDataToDataUtil (conn, &mySrcPath,
             &myTargPath, myRodsEnv, rodsArgs, dataObjCopyInp);
	    if (myTargPath.rodsObjStat != NULL) {
	        freeRodsObjStat (myTargPath.rodsObjStat);
		myTargPath.rodsObjStat = NULL;
	    }
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                  "rsyncCollToCollUtil: rsyncDataToDataUtil failed for %s.stat=%d",
                  myTargPath.outPath, status);
                /* need to set global error here */
                savedStatus = status;
                status = 0;
            }
        } else if (collEnt.objType == COLL_OBJ_T) {
#if 0
            if (strlen (collEnt.collName) <= collLen)
                continue;

            snprintf (targChildPath, MAX_NAME_LEN, "%s%s",
              targColl, collEnt.collName + collLen);
#else
            if ((status = splitPathByKey (
              collEnt.collName, parPath, childPath, '/')) < 0) {
                rodsLogError (LOG_ERROR, status,
                  "rsyncCollToCollUtil:: splitPathByKey for %s error, status = %d",
                  collEnt.collName, status);
                return (status);
            }
            snprintf (targChildPath, MAX_NAME_LEN, "%s/%s",
              targColl, childPath);
#endif


	    if ( rodsArgs->longOption != True ) {   /* only do the sync if no -l option specified */
#ifdef FILESYSTEM_META
                mkCollWithSrcCollMeta (conn, targChildPath, collEnt.collName);
#else
            	mkColl (conn, targChildPath);
#endif
	    }

#if 0
            if (collEnt.specColl.collClass != NO_SPEC_COLL) {
#endif
                /* the child is a spec coll. need to drill down */
                childDataObjCopyInp = *dataObjCopyInp;
		if (collEnt.specColl.collClass != NO_SPEC_COLL)
                    childDataObjCopyInp.srcDataObjInp.specColl = 
		      &collEnt.specColl;
                rstrcpy (myTargPath.outPath, targChildPath, MAX_NAME_LEN);
                rstrcpy (mySrcPath.outPath, collEnt.collName, MAX_NAME_LEN);
                status = rsyncCollToCollUtil (conn, &mySrcPath,
                  &myTargPath, myRodsEnv, rodsArgs, &childDataObjCopyInp);


                if (status < 0 && status != CAT_NO_ROWS_FOUND) {
                    return (status);
                }
#if 0
            }
#endif
	}
    }
    rclCloseCollection (&collHandle);

    if (savedStatus < 0) {
        return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND || 
      status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
        return (0);
    } else {
        return (status);
    }
}

int
initCondForRsync (rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjInp_t *dataObjInp)
{
    char *myResc = NULL;
    char tmpStr[NAME_LEN];

    if (dataObjInp == NULL) {
       rodsLog (LOG_ERROR,
          "initCondForRsync: NULL dataObjOprInp input");
        return (USER__NULL_INPUT_ERR);
    }

    memset (dataObjInp, 0, sizeof (dataObjInp_t));

    if (rodsArgs == NULL) {
	return (0);
    }

    /* always turn on the force flag */
    addKeyVal (&dataObjInp->condInput, FORCE_FLAG_KW, "");

    if (rodsArgs->sizeFlag == True) {
        addKeyVal (&dataObjInp->condInput, VERIFY_BY_SIZE_KW, "");
    }

    if (rodsArgs->all == True) {
        addKeyVal (&dataObjInp->condInput, ALL_KW, "");
    }

#ifdef windows_platform
    dataObjInp->numThreads = NO_THREADING;
#else
    if (rodsArgs->number == True) {
        if (rodsArgs->numberValue == 0) {
            dataObjInp->numThreads = NO_THREADING;
        } else {
            dataObjInp->numThreads = rodsArgs->numberValue;
        }
    }
#endif

    if (rodsArgs->resource == True) {
        if (rodsArgs->resourceString == NULL) {
            rodsLog (LOG_ERROR,
              "initCondForRepl: NULL resourceString error");
            return (USER__NULL_INPUT_ERR);
        } else {
            myResc = rodsArgs->resourceString;
            addKeyVal (&dataObjInp->condInput, DEST_RESC_NAME_KW,
              rodsArgs->resourceString);
        }
    } else if (myRodsEnv != NULL && strlen (myRodsEnv->rodsDefResource) > 0) {
        myResc = myRodsEnv->rodsDefResource;
        addKeyVal (&dataObjInp->condInput, DEST_RESC_NAME_KW,
          myRodsEnv->rodsDefResource);
    }
    if (rodsArgs->age == True) {
        snprintf (tmpStr, NAME_LEN, "%d", rodsArgs->agevalue);
        addKeyVal (&dataObjInp->condInput, AGE_KW, tmpStr);
    }

    return (0);
}
Exemplo n.º 11
0
static mrb_value
read_value(MarshalContext *ctx)
{
	mrb_state *mrb = ctx->mrb;

	char type = ctx->readByte();

	mrb_value value;
	if (mrb->arena_idx > maxArena)
		maxArena = mrb->arena_idx;

	int arena = mrb_gc_arena_save(mrb);

	switch (type)
	{
	case TYPE_NIL :
		value = mrb_nil_value();
		break;

	case TYPE_TRUE :
		value = mrb_true_value();
		break;

	case TYPE_FALSE :
		value = mrb_false_value();
		break;
	case TYPE_FIXNUM :
		value = mrb_fixnum_value(read_fixnum(ctx));
		break;

	case TYPE_BIGNUM :
		value = mrb_fixnum_value(read_bignum(ctx));
		break;
	case TYPE_FLOAT :
		value = mrb_float_value(mrb, read_float(ctx));
		ctx->objects.add(value);
		break;

	case TYPE_STRING :
		value = read_string_value(ctx);
		ctx->objects.add(value);
		break;

	case TYPE_ARRAY :
		value = read_array(ctx);
		break;

	case TYPE_HASH :
		value = read_hash(ctx);
		break;

	case TYPE_SYMBOL :
		value = mrb_symbol_value(read_symbol(ctx));
		break;

	case TYPE_SYMLINK :
		value = mrb_symbol_value(read_symlink(ctx));
		break;

	case TYPE_OBJECT :
		value = read_object(ctx);
		break;

	case TYPE_IVAR :
		value = read_instance_var(ctx);
		break;

	case TYPE_LINK :
		value = read_link(ctx);
		break;

	case TYPE_USERDEF :
		value = read_userdef(ctx);
		ctx->objects.add(value);
		break;

	default :
		CCLOG( "Marshal.load: unsupported value type '%c',gbufsize %d",type,g_buf_size);
		CCAssert(false,"f**k");
		//exit(0);
	}

	mrb_gc_arena_restore(mrb, arena);

	return value;
}