Пример #1
0
bool OperCFThread::MoveNode( FS* srcFs, FSPath& srcPath, FSNode* srcNode, FS* destFs, FSPath& destPath )
{

	if ( srcNode->st.IsLnk() )
	{
		int r = MoveFile( srcFs, srcPath, srcNode, destFs, destPath );

		if ( r < 0 ) { return false; }

		if ( r > 0 && !CopyLink( srcFs, srcPath, srcNode, destFs, destPath, true ) ) { return false; }
	}
	else if ( srcNode->st.IsDir() )
	{
		int r = MoveDir( srcFs, srcPath, srcNode, destFs, destPath );

		if ( r < 0 ) { return false; }

		if ( r > 0 && !CopyDir( srcFs, srcPath, srcNode, destFs, destPath, true ) ) { return false; }

	}
	else
	{
		int r = MoveFile( srcFs, srcPath, srcNode, destFs, destPath );

		if ( r < 0 ) { return false; }

		if ( r > 0 && !CopyFile( srcFs, srcPath, srcNode, destFs, destPath, true ) ) { return false; }
	}

	return true;
}
void GenesisCopyWindow::Copy(const char *filename, const char *destination, const char *destfilename)
////////////////////////////////////////////////////////////////////////
{
	BEntry sourcefile(filename);
	BString text;
	
	if (sourcefile.InitCheck()==B_OK)
	{
/*
		BString text;
		
		text.SetTo("");
		text << filename << "\n" << destination;

		BAlert *myAlert = new BAlert("Copy debug",text.String(),"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
		myAlert->Go();
*/

		if (sourcefile.IsDirectory())
		{
			if (IsRecursiveCopy(filename, destination))
			{
				BString text;
				text << "Recursive copy not allowed.\nPlease check the destination folder.";
			
				BAlert *myAlert = new BAlert("Copy",text.String(),"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
				myAlert->Go();
				Close();
				kill_thread(m_CopyThread);
			}

			CopyDirectory(filename, destination, destfilename);
		}
		else if (sourcefile.IsSymLink())
			CopyLink(filename,destination, destfilename);
		else
			CopyFile(filename, destination, destfilename);
	}
	else if (!m_SkipAllCopyError)
	{
		text << "Error while initializing file:\n\n" << filename;
		
		BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Skip all","Skip",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT);
		myAlert->SetShortcut(0, B_ESCAPE);
		switch (myAlert->Go())
		{
			case 0:
				Close();
				kill_thread(m_CopyThread);
				break;
			case 1:
				m_SkipAllCopyError = true;
				break;
		}	
	}
}
Пример #3
0
bool CDDELink::CopyLink(HWND hOwner, const CDDELink* pLink)
{
	ASSERT(::IsWindow(hOwner));
	ASSERT(pLink != nullptr);
	ASSERT(pLink->Conversation() != nullptr);

	CDDEConv* pConv = pLink->Conversation();

	return CopyLink(hOwner, pConv->Service(), pConv->Topic(), pLink->Item());
}
Пример #4
0
bool OperCFThread::CopyNode(FS *srcFs, FSPath &srcPath, FSNode *srcNode, FS *destFs, FSPath &destPath, bool move)
{
	if (srcNode->st.IsLnk()) {
		 if (!CopyLink(srcFs, srcPath, srcNode, destFs, destPath, move)) return false; 
	} else
	if (srcNode->st.IsDir()) { 
		if (!CopyDir(srcFs, srcPath, srcNode, destFs, destPath, move)) return false; 
	} else {
		if (!CopyFile(srcFs, srcPath, srcNode, destFs, destPath, move)) return false;
	}
	return true;
}
Пример #5
0
bool OperCFThread::CopyNode( FS* srcFs, FSPath& srcPath, FSNode* srcNode, FS* destFs, FSPath& destPath, bool move )
{
	// XXX blame, blame. In tmp panel name has full path. Strip the path from the last item
	stripPathFromLastItem(destPath);

	if ( srcNode->st.IsLnk() )
	{
		if ( !CopyLink( srcFs, srcPath, srcNode, destFs, destPath, move ) ) { return false; }
	}
	else if ( srcNode->st.IsDir() )
	{
		if ( !CopyDir( srcFs, srcPath, srcNode, destFs, destPath, move ) ) { return false; }
	}
	else
	{
		if ( !CopyFile( srcFs, srcPath, srcNode, destFs, destPath, move ) ) { return false; }
	}

	return true;
}
Пример #6
0
static int
CopyObject(char *sourceP, char *targetP, int repl, int link)
/* copy a directory, file, or symbolic link */
{
  struct stat src_stat;
  int rc;

  if (progressCallback)
    if (progressCallback(sourceP) != 0)
      return -1;

  if (periodicCallback)
    if (periodicCallback() != 0)
      return -1;

  if (lstat(sourceP, &src_stat) < 0)
    rc = errno;

  else {

copy_switch:

    switch(src_stat.st_mode & S_IFMT) {

      case S_IFDIR:
        rc = CopyDir(sourceP, targetP, repl, link, &src_stat);
        break;

      case S_IFREG:
        rc = CopyFile(sourceP, targetP, repl, &src_stat);
        break;

      case S_IFLNK:
        if (link)
          rc = CopyLink(sourceP, targetP, repl, &src_stat);
        else if (stat(sourceP, &src_stat) < 0)
          rc = errno;
        else
          goto copy_switch;
        break;

      default:
        rc = EINVAL;
    }
  }

  /*
   * Return code zero means everything is ok;
   * return code -1 means the operation is aborted.
   * In either case, propagated the return code up.
   */
  if (rc <= 0)
    return rc;

  /*
   * Return code > 0 means an error occurred in the last operation.
   * Call the the error callback function.  If the callback returns
   * zero, we return zero; this will cause the error to be ignored.
   * Otherwise we return -1 to signal that the operation is aborted.
   */
  if (!errorCallback)
    return rc;
  else if (errorCallback(sourceP, rc) == 0)
    return 0;
  else
    return -1;
}
void GenesisCopyWindow::CopyDirectory(const char *dirname, const char *destination, const char *destdirname)
////////////////////////////////////////////////////////////////////////
{
	BEntry srcentry(dirname);
	BEntry dstentry;
	char name[B_FILE_NAME_LENGTH];
	BString fulldestdir;
	
	if (srcentry.InitCheck()!=B_OK)
		return;
		
	if (!srcentry.Exists())
		return;
		
	srcentry.GetName(name);	
	
	fulldestdir.SetTo(destination);
	if (destdirname)
		fulldestdir << "/" << destdirname;
	else
		fulldestdir << "/" << name;

	dstentry.SetTo(fulldestdir.String());
	
	if (dstentry.InitCheck()!=B_OK)
		return;
		
	if (!dstentry.Exists())
	{
		if (create_directory(fulldestdir.String(), 0777)!=B_OK)		// TODO: jo a 0777?
			return;
	}

	BDirectory dir;
	
	dir.SetTo(dirname);
	if (dir.InitCheck()==B_OK)
	{
		BEntry entry;
		
		if (dir.GetEntry(&entry)==B_OK)
		{	
			while (dir.GetNextEntry(&entry)==B_OK)			
			{
				entry.GetName(name);
								
				if (entry.IsDirectory())
				{
					BString fullname;
					
					fullname.SetTo(dirname);
					fullname << "/" << name;
					CopyDirectory(fullname.String(), fulldestdir.String());
				}
				else if (entry.IsSymLink())
				{
					BString fullname;
					
					fullname.SetTo(dirname);
					fullname << "/" << name;
					CopyLink(fullname.String(), fulldestdir.String());
				}
				else 
				{
					BString fullname;
					
					fullname.SetTo(dirname);
					fullname << "/" << name;
					CopyFile(fullname.String(), fulldestdir.String());
				}
			}
		}
	}

	// Copy attributes...
	CopyAttr(dirname, fulldestdir.String());
}