Esempio n. 1
0
void File::becomeIfOutdated(File& basefile, int save) {
    if (modTime() < basefile.modTime()) {
        if (verbose) {
            fprintf(stderr,
                    "Updating %s since outdated\n"
                    "  (local file mod time: %d; basefile mod time: %d)",
                    path, modTime(), basefile.modTime());
        }
        if (strcmp(path, program) == 0) {
            // The file we are about to overwrite has the same name as the
            // executing footprint. Moving/removing the file before the copy
            // seems to solve the "Segmentation fault" problem.
            char line[LINE_LENGTH];
            if (save) {
                fprintf(stderr, "Saving old %s\n", path);
                sprintf(line, "mv %s %s.OLD", path, path);
                if (execute(line)) exit(-1);
            } else {
                fprintf(stderr, "Removing %s\n", path);
                sprintf(line, "rm %s", path);
                if (execute(line)) exit(-1);
            }
            become(basefile, 0);
        } else {
            become(basefile, save);
        }
    } else {
        if (verbose) {
            fprintf(stderr,
                    "Not updating %s since not outdated\n"
                    "  (local file mod time: %d; basefile mod time: %d)",
                    path, modTime(), basefile.modTime());
        }
    }
}
Esempio n. 2
0
// -----------------------------------------------------------------------------
// CSendObject::SetFileProperties
// -----------------------------------------------------------------------------
//
void CSendObject::SetFileProperties()
    {
    PRINT1( _L( "MM MTP => CSendObject::SetFileProperties iProtectionStatus = %d" ), iProtectionStatus );

    if ( iFileReceived != NULL )
        {
        if ( iProtectionStatus == EMTPProtectionNoProtection
            || iProtectionStatus == EMTPProtectionReadOnly )
            {
            TInt err = KErrNone;
            if ( iProtectionStatus == EMTPProtectionNoProtection )
                {
                err = iFileReceived->File().SetAtt( KEntryAttNormal, KEntryAttReadOnly );
                }
            else
                {
                err = iFileReceived->File().SetAtt( KEntryAttReadOnly, KEntryAttNormal );
                }
    
            if ( err != KErrNone )
                {
                PRINT1( _L( "MM MTP <> CSendObject::SetFileProperties SetAtt err = %d" ), err );
                }
            }

        if( iDateMod != NULL )
            {
            TTime modTime( 0 );
            TInt err = MmMtpDpUtility::DesToTTime( *iDateMod, modTime );
            if( err == KErrNone )
                {
                err = iFileReceived->File().SetModified( modTime );
                PRINT1( _L( "MM MTP <> CSendObject::SetFileProperties SetModified err = %d" ), err );
                }
            }

        // Close the file after SetFileProperties to make sure other process won't open
        // the file successfully right at the time calling RFile::SetAtt.
        if ( iObjectSize > 0 )
            {
            delete iFileReceived;
            iFileReceived = NULL;
            }
        else
            iFileReceived->File().Close();
        }

    PRINT( _L( "MM MTP <= CSendObject::SetFileProperties" ) );
    }
Esempio n. 3
0
pwr_tTime wb_orep::treeModTime()
{
  pwr_tStatus sts;
  pwr_tTime t = modTime();
  pwr_tTime tchild;
  wb_orep *after;

  for ( wb_orep *child = first( &sts); 
        ODD(sts);
	child = after) {
    child->ref();

    tchild = child->treeModTime();
    if ( time_Acomp( &tchild, &t) == 1)
      t = tchild;

    after = child->after( &sts);
    child->unref();
  }
  return t;
}
int CommonTools::getdir (std::string dir, std::vector<std::string> &files)
{
  DIR *dp;
  struct stat st;
  struct dirent *dirp;

  if((dp  = opendir(dir.c_str())) == NULL) {
    std::cout << "Error(" << errno << ") opening " << dir << std::endl;
    return errno;
  }
  while ((dirp = readdir(dp)) != NULL) {
    std::string fullpath=dir+std::string("/")+std::string(dirp->d_name);
    stat (fullpath.c_str(), &st);
    time_t modified_last = st.st_ctime;
    std::string modTime(asctime(localtime ( &modified_last ) ) );
    std::string file(dirp->d_name);
    files.push_back(file);
  }
  closedir(dp);
  return 0;
}