コード例 #1
0
   // PfmFormatterDispatch::Delete
void CCALL Volume::Delete( PfmMarshallerDeleteOp* op, void* formatterUse)
{
   int64_t openId = op->OpenId();
   int64_t parentFileId = op->ParentFileId();
   const PfmNamePart* endName = op->EndName();
   int64_t writeTime = op->WriteTime();
   int perr;
   File* file;

   perr = FindOpenFile( openId, &file);
   if (!perr)
   {
      if (file == &root)
      {
            // Can't delete root.
         perr = pfmErrorAccessDenied;
      }
      else if (!file->name)
      {
            // Already deleted.
      }
      else if (file->fileType == pfmFileTypeFolder && file->data.folder.firstChild)
      {
            // Don't allow non empty folder to be deleted
         perr = pfmErrorNotEmpty;
      }
      else
      {
         file->Delete( writeTime, false/*leaveChildren*/);
      }
   }

   op->Complete( perr);
}
コード例 #2
0
   // PfmFormatterDispatch::MoveReplace
void CCALL Volume::MoveReplace( PfmMarshallerMoveReplaceOp* op, void* formatterUse)
{
   int64_t sourceOpenId = op->SourceOpenId();
   int64_t sourceParentFileId = op->SourceParentFileId();
   const PfmNamePart* sourceEndName = op->SourceEndName();
   int64_t targetOpenId = op->TargetOpenId();
   int64_t targetParentFileId = op->TargetParentFileId();
   const PfmNamePart* targetEndName = op->TargetEndName();
   uint8_t/*bool*/ deleteSource = op->DeleteSource();
   int64_t writeTime = op->WriteTime();
   int perr;
   File* file;
   File* target;

   perr = FindOpenFile( sourceOpenId, &file);
   if (!perr)
   {
      perr = FindOpenFile( targetOpenId, &target);
      if (!perr)
      {
         if (target == &root)
         {
               // Can't replace root.
            perr = pfmErrorAccessDenied;
         }
         else if (!target->name)
         {
            perr = pfmErrorDeleted;
         }
         else if (file->sibPrev && !deleteSource)
         {
               // Links are not supported.
            perr = pfmErrorInvalid;
         }
         else if (file == target)
         {
            perr = pfmErrorInvalid;
         }
         else
         {
            perr = file->Move( target->parent, target->sibPrev, target->name, writeTime);
            if (!perr)
            {
               target->Delete( writeTime, false/*leaveChildren*/);
            }
         }
      }
   }

   op->Complete( perr);
}
コード例 #3
0
   // PfmFormatterDispatch::Replace
void CCALL Volume::Replace( PfmMarshallerReplaceOp* op, void* formatterUse)
{
   int64_t targetOpenId = op->TargetOpenId();
   int64_t targetParentFileId = op->TargetParentFileId();
   const PfmNamePart* targetEndName = op->TargetEndName();
   uint8_t createFileFlags = op->CreateFileFlags();
   int64_t writeTime = op->WriteTime();
   int64_t newCreateOpenId = op->NewCreateOpenId();
   int perr;
   PfmOpenAttribs openAttribs = zeroOpenAttribs;
   File* target;
   File* file;

   perr = FindOpenFile( targetOpenId, &target);
   if (!perr)
   {
      if (target == &root)
      {
            // Can't replace root.
         perr = pfmErrorAccessDenied;
      }
      else if (!target->name)
      {
         perr = pfmErrorDeleted;
      }
      else
      {
         perr = FileFactory( target->parent, target->sibPrev, target->name, target->fileType, createFileFlags, writeTime, &file);
         if (!perr)
         {
            target->Delete( writeTime, false/*leaveChildren*/);
            file->Open( newCreateOpenId, &openAttribs, 0, 0);
         }
      }
   }

   op->Complete( perr, &openAttribs, 0);
}
コード例 #4
0
ファイル: filcreat.cpp プロジェクト: 9a3eedi/Droidsound
bool UpdateExistingShortName(char *Name,wchar *NameW)
{
  FindData fd;
  if (!FindFile::FastFind(Name,NameW,&fd))
    return(false);
  if (*fd.Name==0 || *fd.ShortName==0)
    return(false);
  if (stricomp(PointToName(fd.Name),fd.ShortName)==0 ||
      stricomp(PointToName(Name),fd.ShortName)!=0)
    return(false);

  char NewName[NM];
  for (int I=0;I<10000;I+=123)
  {
    strncpyz(NewName,Name,ASIZE(NewName));
    sprintf(PointToName(NewName),"rtmp%d",I);
    if (!FileExist(NewName))
      break;
  }
  if (FileExist(NewName))
    return(false);
  char FullName[NM];
  strncpyz(FullName,Name,ASIZE(FullName));
  strcpy(PointToName(FullName),PointToName(fd.Name));
  if (!MoveFile(FullName,NewName))
    return(false);
  File KeepShortFile;
  bool Created=false;
  if (!FileExist(Name))
    Created=KeepShortFile.Create(Name);
  MoveFile(NewName,FullName);
  if (Created)
  {
    KeepShortFile.Close();
    KeepShortFile.Delete();
  }
  return(true);
}
コード例 #5
0
void JUnitOutput::WriteToFile(const Uri& URI, 
                              const TestResultCollector& Results)
{
    // ensure that a new log will be written
    File output;
    output.SetLocation(URI);
    output.Delete();

    FileStream out;
    out.Open(URI, FileAccessMode::Write, FileAccessPriority::DelayReadWrite);
    if (out.CanWrite())
    {
        //start suites
        String tag("<testsuites>\n", sizeof("<testsuites>\n"));
        out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
        for(UInt32 i = 0; i<Results.TestResults().Count(); ++i)
        {
            //start a suite
            tag=String::Format(String("<testsuite error=\"%u\" failures=\"%u\" hostname=\"RadonFramework-TestEnvoirement\" name=\"%s\" tests=\"%u\" time=\"%.3f\" timestamp=\"%s\" id=\"%u\" package=\"%u\">\n",sizeof(
                                      "<testsuite error=\"%u\" failures=\"%u\" hostname=\"RadonFramework-TestEnvoirement\" name=\"%s\" tests=\"%u\" time=\"%.3f\" timestamp=\"%s\" id=\"%u\" package=\"%u\">\n")),
                                Results.TestResults()[i].TestsWithError,
                                Results.TestResults()[i].TestsWithFailure,
                                Results.TestResults()[i].SuiteName.c_str(),
                                Results.TestResults()[i].TestResults.Count(),
                                Results.TestResults()[i].TotalTime,
                                "2007-11-02T23:13:49",
                                0,
                                0);
            out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0 ,tag.Length());
            for(UInt32 j = 0; j<Results.TestResults()[i].TestResults.Count(); ++j)
            {
                //start testcase
                tag=String::Format(String("<testcase classname=\"%s\" name=\"%s\" time=\"%d\">\n", sizeof(
                                        "<testcase classname=\"%s\" name=\"%s\" time=\"%d\">\n")),
                                    "",
                                    Results.TestResults()[i].TestResults[j].Name().c_str(),
                                    Results.TestResults()[i].TestResults[j].TimeRequired().Ticks());
                out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
                // test failed
                if (!Results.TestResults()[i].TestResults[j].Passed())
                {
                    tag=String::Format(String("<error message=\"%s\" type=\"%s\">%s\n", sizeof(
                                            "<error message=\"%s\" type=\"%s\">%s\n")),
                                        "",
                                        "",
                                        "");
                    out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
                    tag="</error>\n";
                    out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
                }
                // test raise an exception
                if (Results.TestResults()[i].TestResults[j].Error())
                {
                    tag=String::Format(String("<failure message=\"%s\" type=\"%s\">%s\n",sizeof(
                        "<failure message=\"%s\" type=\"%s\">%s\n")),
                        "",
                        "",
                        "");
                    out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
                    tag="</failure>\n";
                    out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
                }
                //end testcase
                tag="</testcase>\n";
                out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
            }
            //end the suite
            tag="</testsuite>\n";
            out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
        }
        //end suites
        tag="</testsuites>\n";
        out.Write(reinterpret_cast<const UInt8*>(tag.c_str()), 0, tag.Length());
    }
}
コード例 #6
0
ファイル: Changeset.cpp プロジェクト: euler0/Helium
void Changeset::Delete( File& file, const OpenFlag flags ) const
{
  file.Delete( flags, m_Id );
}
コード例 #7
0
ファイル: filcreat.cpp プロジェクト: ccarpo/ComicStreamer
// If we find a file, which short name is equal to 'Name', we try to change
// its short name, while preserving the long name. It helps when unpacking
// an archived file, which long name is equal to short name of already
// existing file. Otherwise we would overwrite the already existing file,
// even though its long name does not match the name of unpacking file.
bool UpdateExistingShortName(const wchar *Name)
{
  wchar LongPathName[NM];
  DWORD Res=GetLongPathName(Name,LongPathName,ASIZE(LongPathName));
  if (Res==0 || Res>=ASIZE(LongPathName))
    return false;
  wchar ShortPathName[NM];
  Res=GetShortPathName(Name,ShortPathName,ASIZE(ShortPathName));
  if (Res==0 || Res>=ASIZE(ShortPathName))
    return false;
  wchar *LongName=PointToName(LongPathName);
  wchar *ShortName=PointToName(ShortPathName);

  // We continue only if file has a short name, which does not match its
  // long name, and this short name is equal to name of file which we need
  // to create.
  if (*ShortName==0 || wcsicomp(LongName,ShortName)==0 ||
      wcsicomp(PointToName(Name),ShortName)!=0)
    return false;

  // Generate the temporary new name for existing file.
  wchar NewName[NM];
  *NewName=0;
  for (int I=0;I<10000 && *NewName==0;I+=123)
  {
    // Here we copy the path part of file to create. We'll make the temporary
    // file in the same folder.
    wcsncpyz(NewName,Name,ASIZE(NewName));

    // Here we set the random name part.
    swprintf(PointToName(NewName),ASIZE(NewName),L"rtmp%d",I);
    
    // If such file is already exist, try next random name.
    if (FileExist(NewName))
      *NewName=0;
  }

  // If we could not generate the name not used by any other file, we return.
  if (*NewName==0)
    return false;
  
  // FastFind returns the name without path, but we need the fully qualified
  // name for renaming, so we use the path from file to create and long name
  // from existing file.
  wchar FullName[NM];
  wcsncpyz(FullName,Name,ASIZE(FullName));
  SetName(FullName,LongName,ASIZE(FullName));
  
  // Rename the existing file to randomly generated name. Normally it changes
  // the short name too.
  if (!MoveFile(FullName,NewName))
    return false;

  // Now we need to create the temporary empty file with same name as
  // short name of our already existing file. We do it to occupy its previous
  // short name and not allow to use it again when renaming the file back to
  // its original long name.
  File KeepShortFile;
  bool Created=false;
  if (!FileExist(Name))
    Created=KeepShortFile.Create(Name,FMF_WRITE|FMF_SHAREREAD);

  // Now we rename the existing file from temporary name to original long name.
  // Since its previous short name is occupied by another file, it should
  // get another short name.
  MoveFile(NewName,FullName);

  if (Created)
  {
    // Delete the temporary zero length file occupying the short name,
    KeepShortFile.Close();
    KeepShortFile.Delete();
  }
  // We successfully changed the short name. Maybe sometimes we'll simplify
  // this function by use of SetFileShortName Windows API call.
  // But SetFileShortName is not available in older Windows.
  return true;
}
コード例 #8
0
ファイル: filcreat.cpp プロジェクト: pfalcon/PhotoTvViewer
// If we find a file, which short name is equal to 'Name', we try to change
// its short name, while preserving the long name. It helps when unpacking
// an archived file, which long name is equal to short name of already
// existing file. Otherwise we would overwrite the already existing file,
// even though its long name does not match the name of unpacking file.
bool UpdateExistingShortName(wchar *Name)
{
  // 'Name' is the name of file which we want to create. Let's check
  // if file with such name is exist. If it does not, we return.
  FindData fd;
  if (!FindFile::FastFind(NULL,Name,&fd))
    return(false);

  // We continue only if file has a short name, which does not match its
  // long name, and this short name is equal to name of file which we need
  // to create.
  if (*fd.ShortName==0 || wcsicomp(PointToName(fd.NameW),fd.ShortName)==0 ||
      wcsicomp(PointToName(Name),fd.ShortName)!=0)
    return(false);

  // Generate the temporary new name for existing file.
  wchar NewName[NM];
  *NewName=0;
  for (int I=0;I<10000 && *NewName==0;I+=123)
  {
    // Here we copy the path part of file to create. We'll make the temporary
    // file in the same folder.
    wcsncpyz(NewName,Name,ASIZE(NewName));

    // Here we set the random name part.
    sprintfw(PointToName(NewName),ASIZE(NewName),L"rtmp%d",I);
    
    // If such file is already exist, try next random name.
    if (FileExist(NULL,NewName))
      *NewName=0;
  }

  // If we could not generate the name not used by any other file, we return.
  if (*NewName==0)
    return(false);
  
  // FastFind returns the name without path, but we need the fully qualified
  // name for renaming, so we use the path from file to create and long name
  // from existing file.
  wchar FullName[NM];
  wcsncpyz(FullName,Name,ASIZE(FullName));
  wcscpy(PointToName(FullName),PointToName(fd.NameW));
  
  // Rename the existing file to randomly generated name. Normally it changes
  // the short name too.
  if (!MoveFileW(FullName,NewName))
    return(false);

  // Now we need to create the temporary empty file with same name as
  // short name of our already existing file. We do it to occupy its previous
  // short name and not allow to use it again when renaming the file back to
  // its original long name.
  File KeepShortFile;
  bool Created=false;
  if (!FileExist(NULL,Name))
    Created=KeepShortFile.Create(NULL,Name);

  // Now we rename the existing file from temporary name to original long name.
  // Since its previous short name is occupied by another file, it should
  // get another short name.
  MoveFileW(NewName,FullName);

  if (Created)
  {
    // Delete the temporary zero length file occupying the short name,
    KeepShortFile.Close();
    KeepShortFile.Delete();
  }
  // We successfully changed the short name. Maybe sometimes we'll simplify
  // this function by use of SetFileShortName Windows API call.
  // But SetFileShortName is not available in older Windows.
  return(true);
}