/**
 * @brief 执行ls命令 
 * @details 列出指定目录的多个文件
 * @param[in] all        是否输出全部文件,包括隐藏文件,以及.和..
 * @param[in] almost_all 是否“几乎全部”输出,包括隐藏文件,不包括.和..
 * @param[in] long_list  是否按长列表方式输出
 * @param[in] list_path  需要列出文件的目录数组
 * @return 成功返回true,失败返回false
 */
bool ls( bool all, bool almost_all, bool long_list, const char * const * const list_path )
{
	char absolute_path[MAX_PATH];
	const char * const * p = NULL;

	if ( list_path == NULL )
		output_files(current_path, all, almost_all, long_list);
	else
	{
		for ( p = list_path; (*p) != NULL; ++ p )
		{
			get_absolute_path(absolute_path, *p);
			output_files(absolute_path, all, almost_all, long_list);
		}
	}
	return true;
}
Exemplo n.º 2
0
bool VanillaToGrid::vanillaToGrid(classad::ClassAd * ad, int target_universe, const char * gridresource, bool is_sandboxed)
{
	ASSERT(ad);

	/* TODO:
		- If job fails to specify transfer_input_files but has some (relying on
		  a shared filesystem), we're doomed.  Probably
		  if(should_transfer_files is NO, we should just fail.
		  (We'll do the right thing if grid_type=condor, but not other
		  grid types.)

		- Job may be relying on Condor automatically transfer output files.  If
		  transfer_output_files is set, we're probably good (again, assuming no
		  shared filesystem).  If it's not set, we can't tell the difference
		  between no output files and "everything"
		  (We'll do the right thing if grid_type=condor, but not other
		  grid types.)

		- I'm leaving WhenToTransferFiles alone.  It should work fine.

		- Should I leave FilesystemDomain in?  May be useful, but
		simultaneously will likely do the Wrong Thing on the remote
		side
	*/

	MyString remoteattr;
	remoteattr = "Remote_";
	remoteattr += ATTR_JOB_UNIVERSE;

	// Things we don't need or want
	ad->Delete(ATTR_CLUSTER_ID); // Definate no-no
	ad->Delete(ATTR_PROC_ID);


	ad->Delete(ATTR_BUFFER_BLOCK_SIZE);
	ad->Delete(ATTR_BUFFER_SIZE);
	ad->Delete(ATTR_BUFFER_SIZE);
	ad->Delete("CondorPlatform"); // TODO: Find #define
	ad->Delete("CondorVersion");  // TODO: Find #define
	ad->Delete(ATTR_CORE_SIZE);
	ad->Delete(ATTR_GLOBAL_JOB_ID); // Store in different ATTR here?
	//ad->Delete(ATTR_OWNER); // How does schedd filter? 
	ad->Delete(ATTR_Q_DATE);
	ad->Delete(ATTR_JOB_REMOTE_WALL_CLOCK);
	ad->Delete(ATTR_SERVER_TIME);
	ad->Delete(ATTR_AUTO_CLUSTER_ID);
	ad->Delete(ATTR_AUTO_CLUSTER_ATTRS);
	ad->Delete(ATTR_TOTAL_SUBMIT_PROCS);
	ad->Delete( ATTR_STAGE_IN_FINISH );
	ad->Delete( ATTR_STAGE_IN_START );

	// We aren't going to forward updates to this attribute,
	// so strip it out.
	// We do evaluate it locally in the source job ad.
	ad->Delete(ATTR_TIMER_REMOVE_CHECK);

	ad->Delete("SUBMIT_" ATTR_JOB_IWD); // the presence of this would prevent schedd from rewriting spooled iwd

	// Stuff to reset
	ad->InsertAttr(ATTR_JOB_STATUS, 1); // Idle
	ad->InsertAttr(ATTR_JOB_REMOTE_USER_CPU, 0.0);
	ad->InsertAttr(ATTR_JOB_REMOTE_SYS_CPU, 0.0);
	ad->InsertAttr(ATTR_JOB_EXIT_STATUS, 0);
	ad->InsertAttr(ATTR_COMPLETION_DATE, 0);
	ad->InsertAttr(ATTR_JOB_LOCAL_SYS_CPU, 0.0);
	ad->InsertAttr(ATTR_JOB_LOCAL_USER_CPU, 0.0);
	ad->InsertAttr(ATTR_NUM_CKPTS, 0);
	ad->InsertAttr(ATTR_NUM_RESTARTS, 0);
	ad->InsertAttr(ATTR_NUM_SYSTEM_HOLDS, 0);
	ad->InsertAttr(ATTR_JOB_COMMITTED_TIME, 0);
	ad->InsertAttr(ATTR_COMMITTED_SLOT_TIME, 0);
	ad->InsertAttr(ATTR_CUMULATIVE_SLOT_TIME, 0);
	ad->InsertAttr(ATTR_TOTAL_SUSPENSIONS, 0);
	ad->InsertAttr(ATTR_LAST_SUSPENSION_TIME, 0);
	ad->InsertAttr(ATTR_CUMULATIVE_SUSPENSION_TIME, 0);
	ad->InsertAttr(ATTR_COMMITTED_SUSPENSION_TIME, 0);
	ad->InsertAttr(ATTR_ON_EXIT_BY_SIGNAL, false);


	//ad->Delete(ATTR_MY_TYPE); // Should be implied
	//ad->Delete(ATTR_TARGET_TYPE); // Should be implied.

	// Remap the universe
	classad::ExprTree * tmp;
	tmp = ad->Lookup(ATTR_JOB_UNIVERSE);
	if( ! tmp ) {
		EXCEPT("VanillaToGrid: job ad lacks universe");
	}
	classad::ExprTree * olduniv = tmp->Copy();
	if( ! olduniv) {
		EXCEPT("Unable to copy old universe");
	}

	ad->InsertAttr(ATTR_JOB_UNIVERSE, target_universe);
	ad->Insert(remoteattr.Value(), olduniv, false);
		// olduniv is now controlled by ClassAd

	if( target_universe == CONDOR_UNIVERSE_GRID ) {
		ad->Delete(ATTR_CURRENT_HOSTS);

		// Set the grid resource
		if( gridresource ) {
			ad->InsertAttr(ATTR_GRID_RESOURCE, gridresource);
		}

		// Grid universe, unlike vanilla universe expects full output
		// paths for Out/Err.  In vanilla, these are basenames that
		// point into TransferOutputRemaps.  If the job is sandboxed,
		// then our remaps will apply when we fetch the output from
		// the completed job.  That's fine, so we leave the remaps
		// in place in that case.  Otherwise, we undo the remaps and
		// let the grid job write directly to the correct output
		// paths.

		std::string remaps;
		ad->EvaluateAttrString(ATTR_TRANSFER_OUTPUT_REMAPS,remaps);
		if( !is_sandboxed && remaps.size() ) {
			MyString remap_filename;
			std::string filename,filenames;

				// Don't need the remaps in the grid copy of the ad.
			ad->Delete(ATTR_TRANSFER_OUTPUT_REMAPS);

			if( ad->EvaluateAttrString(ATTR_JOB_OUTPUT,filename) ) {
				if( filename_remap_find(remaps.c_str(),filename.c_str(),remap_filename) ) {
					ad->InsertAttr(ATTR_JOB_OUTPUT,remap_filename.Value());
				}
			}

			if( ad->EvaluateAttrString(ATTR_JOB_ERROR,filename) ) {
				if( filename_remap_find(remaps.c_str(),filename.c_str(),remap_filename) ) {
					ad->InsertAttr(ATTR_JOB_ERROR,remap_filename.Value());
				}
			}

				// TransferOutputFiles appears to be different.  If it
				// behaved similarly to Out/Err, then we would want to
				// do the following:
#if 0
			if( ad->EvaluateAttrString(ATTR_TRANSFER_OUTPUT_FILES,filename) ) {
				StringList output_files(filename.c_str(),",");
				StringList new_list;
				char const *fname;

				output_files.rewind();
				while( (fname=output_files.next()) ) {
					if( filename_remap_find(remaps.c_str(),fname,remap_filename) )
						{
							new_list.append(remap_filename.Value());
						}
					else {
						new_list.append(fname);
					}
				}

				char *new_list_str = new_list.print_to_string();
				ASSERT( new_list_str );

				ad->InsertAttr(ATTR_TRANSFER_OUTPUT_FILES,new_list_str);

				free( new_list_str );
			}
#endif

		}
	}

	return true;
}