コード例 #1
0
ファイル: utils.cpp プロジェクト: Civil/cantata
/*
 * Set file permissions.
 * If user is a memeber of "users" group, then set file as owned by and writeable by "users" group.
 */
void Utils::setFilePerms(const QString &file, const char *groupName)
{
    //
    // Clear any umask before setting file perms
    mode_t oldMask(umask(0000));
    gid_t gid=getGroupId(groupName);
    QByteArray fn=QFile::encodeName(file);
    ::chmod(fn.constData(), 0==gid ? 0644 : 0664);
    if (0!=gid) {
        int rv=::chown(fn.constData(), geteuid(), gid);
        Q_UNUSED(rv)
    }
コード例 #2
0
void ClusteredClearing::crossMUX ( double probM, Cluster &clus, char** mates,
   int numMates, char* off, int size ) {
   
   int numDiferences = 0;
   string oldMask (clus.mask);
   //memcpy( oldMask, clus.mask, size * sizeof( char ) );
   memcpy( off, population[clus.cIndex], size * sizeof( char ) );
      
   int *perm = new int[ size ];
   random->RandPerm( perm, size );
      
   if ( !repulse ) { // probM -> chance to get bits from mates
    
      for ( int i = 0; i < size; i++ ) {
      
         int cIndex = perm[ i ];
         
         // oldMask = 0 bit protected -> do nothing
         if ( oldMask.compare(cIndex,1,"1") == 0 ) {
            double probs1 = 0;
            double probChange = 0;
   
            for ( int j = 0; j < numMates; j++ ) {
               probs1 += mates[ j ][ cIndex ];
            }
   
            probs1 = probs1 / numMates;
            
            if ( off[ cIndex ] == 1 )
               probChange = 1.0 - probs1;
            else
               probChange = probs1;
            
            // If no change -> flip random unprotected bit
            if ( random->Rand() < ( probChange * probM ) ) {
               off[ cIndex ] = 1 - off[ cIndex ];
               numDiferences++;
               clus.numProtected++;
               clus.mask.replace(cIndex,1,"0");
            }
         }
      }
   } else { // Repulse -> probM = chance to not get bits from mates
    
      for ( int i = 0; i < size; i++ ) {
      
         int cIndex = perm[ i ];
      
         if ( oldMask.compare(cIndex,1,"1") == 0 ) {
   
            double probs1 = 0;
   
            double probChange = 0;
   
            for ( int j = 0; j < numMates; j++ ) {
               probs1 += mates[ j ][ cIndex ];

            }
   
            probs1 = probs1 / numMates;
   
            if ( off[ cIndex ] == 0 ) // repulsa
               probChange = 1.0 - probs1;
            else
               probChange = probs1;
   
            if ( random->Rand() < ( probChange * probM ) ) {
               off[ cIndex ] = 1 - off[ cIndex ];
               numDiferences++;
               clus.numProtected++;
               clus.mask.replace(cIndex,1,"0");
            }
         }
      }
   }
   
   // Si tras recorrer offspring no cambiamos ningún bit, cambiamos uno 
   //  aleatoriamente que no este protegido
   if ( numDiferences == 0 ) {
    
      for ( int i = 0; i < size; i++ ) {
      
         if ( oldMask.compare(perm[i],1,"1") == 0) {
            off[ perm[ i ] ] = 1 - off[ perm[ i ] ];
            numDiferences++;
            clus.numProtected++;
            clus.mask.replace(perm[i],1,"0");
            break;
         }
      }
   }
  
   delete [] perm;
   //delete [] oldMask;
}