Determine if rollover should occur.

        Basically, see if the supplied record would cause the file to exceed
        the size limit we have.
324859
def shouldRollover(self, record):
        
        if self.maxBytes > 0:  # are we rolling over?
            msg = "%s\n" % self.format(record)
            self.stream.seek(0, 2)  # due to non-posix-compliant win feature
            if self.stream.tell() + len(msg) >= self.maxBytes:
                return 1
        return 0
202728
def check_disk_usage(filehandle, meta):
    
    # limit it at twenty kilobytes if no default is provided
    MAX_DISK_USAGE = current_app.config.get('MAX_DISK_USAGE', 20 * 1024)
    CURRENT_USAGE = really_bad_du(current_app.config['UPLOAD_PATH'])
    filehandle.seek(0, os.SEEK_END)

    if CURRENT_USAGE + filehandle.tell() > MAX_DISK_USAGE:
        filehandle.close()
        raise UploadError("Upload exceeds allotment.")
    filehandle.seek(0)
    return filehandle
296971
void rollIfNeeded() throws IOException {
    if (numberOfParts == 1 || numberOfFiles < 1) {
      return;
    }
    filesCount++;
    if (filesCount % filesPerRoll == 0) {
      out.close();
      currentPart++;
      createOutputStream();
    }
  }
322246
protected void integrityCheck() throws DataStoreException
    {
        try
        {
            //========================
            // 1 - Check files sizes
            //========================
            // -- Allocation table
            long atFileSize = allocationTableRandomAccessFile.length();
            if (atFileSize < AT_HEADER_SIZE+AT_BLOCK_SIZE) /* Should have at least one entry */
                throw new DataStoreException("Allocation table is truncated : "+allocationTableFile.getAbsolutePath());
            
            // Read some header fields
            FileInputStream inFile = new FileInputStream(allocationTableFile);
            DataInputStream in = new DataInputStream(new BufferedInputStream(inFile,16384));
            int blockCount = in.readInt();
            int blockSize  = in.readInt();
            int firstBlock = in.readInt();
            // Fix AT size
            long expectedATFileSize = AT_HEADER_SIZE+AT_BLOCK_SIZE*(long)blockCount;
            if (atFileSize != expectedATFileSize)
            {
                log.error("["+descriptor.getName()+"] Allocation table has an invalid size (actual:"+atFileSize+",expected:"+expectedATFileSize+"), fixing.");
                allocationTableRandomAccessFile.setLength(expectedATFileSize);
            }
            // Fix data size
            long dataFileSize = dataRandomAccessFile.length();
            long expectedDataFileSize = (long)blockSize*blockCount;
            if (dataFileSize != expectedDataFileSize)
            {
                log.error("["+descriptor.getName()+"] Data file has an invalid size (actual:"+dataFileSize+",expected:"+expectedDataFileSize+"), fixing.");
                dataRandomAccessFile.setLength(expectedDataFileSize);
            }
            
            //============================
            // 2 - Check allocation table
            //============================
            // Read the AT into memory
            byte[] flags        = new byte[blockCount];
            int[] allocatedSize = new int[blockCount];
            int[] previousBlock = new int[blockCount];
            int[] nextBlock     = new int[blockCount];
            int blocksInUse = 0;
            int msgCount = 0;
            for (int n = 0 ; n < blockCount ; n++)
            {
                flags[n]         = in.readByte();
                allocatedSize[n] = in.readInt();
                previousBlock[n] = in.readInt();
                nextBlock[n]     = in.readInt();
                if (allocatedSize[n] != -1)
                {
                    blocksInUse++;
                    if ((flags[n] & FLAG_START_BLOCK) > 0)
                        msgCount++;
                }
            }
            in.close();
            log.debug("["+descriptor.getName()+"] Blocks in use before fix : "+blocksInUse);
            log.debug("["+descriptor.getName()+"] Messages count before fix : "+msgCount);
            
            // Fix first block index
            boolean changed = false;
            if (firstBlock < -1 || firstBlock >= blockCount)
            {
                log.error("["+descriptor.getName()+"] Invalid allocation table first block index ("+firstBlock+"), guessing new one ...");
                firstBlock = guessFirstBlockIndex(blockCount, allocatedSize, nextBlock);
                log.debug("["+descriptor.getName()+"] Guessed first block index : "+firstBlock);
                changed = true;
            }
            
            // Recover table
            if (msgCount == 0)
            {
                if (firstBlock == -1)
                {
                    // Table is empty, cleanup dirty entries
                    changed = changed || cleanupEmptyBlocks(blockCount, flags, allocatedSize, previousBlock, nextBlock);
                }
                else
                {
                    log.error("["+descriptor.getName()+"] First block index should be -1, clearing ...");
                    firstBlock = -1;
                    changed = true;
                }
            }
            else
            {
                if (firstBlock == -1)
                {
                    log.error("["+descriptor.getName()+"] Invalid first block index, guessing value ...");
                    firstBlock = guessFirstBlockIndex(blockCount, allocatedSize, nextBlock);
                    log.debug("["+descriptor.getName()+"] Guessed first block index : "+firstBlock);
                    changed = true;
                }
     
                changed = changed || fixBlocks(blockCount, blockSize, firstBlock, flags, allocatedSize, previousBlock, nextBlock);
                changed = changed || cleanupEmptyBlocks(blockCount, flags, allocatedSize, previousBlock, nextBlock);
            }
            
            // Update the allocation file table
            if (changed)
            {
                // Re-compute size
                msgCount = 0;
                blocksInUse = 0;
                for (int n = 0 ; n < blockCount ; n++)
                {
                    if (allocatedSize[n] != -1) 
                    {
                        blocksInUse++;
                        if ((flags[n] & FLAG_START_BLOCK) > 0)
                            msgCount++;
                    }
                }
                log.debug("["+descriptor.getName()+"] Blocks in use after fix : "+blocksInUse);
                log.debug("["+descriptor.getName()+"] Messages count after fix : "+msgCount);
                
                log.debug("["+descriptor.getName()+"] Allocation table was altered, saving ...");
                allocationTableRandomAccessFile.seek(AT_HEADER_FIRSTBLOCK_OFFSET);
                allocationTableRandomAccessFile.writeInt(firstBlock);
                for (int n = 0 ; n < blockCount ; n++)
                {
                    byte[] allocationBlock = new byte[AT_BLOCK_SIZE];

                    // Regroup I/O to improve performance
                    allocationBlock[AB_FLAGS_OFFSET]       = flags[n];
                    allocationBlock[AB_ALLOCSIZE_OFFSET]   = (byte)((allocatedSize[n] >>> 24) & 0xFF);
                    allocationBlock[AB_ALLOCSIZE_OFFSET+1] = (byte)((allocatedSize[n] >>> 16) & 0xFF);
                    allocationBlock[AB_ALLOCSIZE_OFFSET+2] = (byte)((allocatedSize[n] >>>  8) & 0xFF);
                    allocationBlock[AB_ALLOCSIZE_OFFSET+3] = (byte)((allocatedSize[n] >>>  0) & 0xFF);
                    allocationBlock[AB_PREVBLOCK_OFFSET]   = (byte)((previousBlock[n] >>> 24) & 0xFF);
                    allocationBlock[AB_PREVBLOCK_OFFSET+1] = (byte)((previousBlock[n] >>> 16) & 0xFF);
                    allocationBlock[AB_PREVBLOCK_OFFSET+2] = (byte)((previousBlock[n] >>>  8) & 0xFF);
                    allocationBlock[AB_PREVBLOCK_OFFSET+3] = (byte)((previousBlock[n] >>>  0) & 0xFF);
                    allocationBlock[AB_NEXTBLOCK_OFFSET]   = (byte)((nextBlock[n] >>> 24) & 0xFF);
                    allocationBlock[AB_NEXTBLOCK_OFFSET+1] = (byte)((nextBlock[n] >>> 16) & 0xFF);
                    allocationBlock[AB_NEXTBLOCK_OFFSET+2] = (byte)((nextBlock[n] >>>  8) & 0xFF);
                    allocationBlock[AB_NEXTBLOCK_OFFSET+3] = (byte)((nextBlock[n] >>>  0) & 0xFF);
                    
                    allocationTableRandomAccessFile.seek(AT_HEADER_SIZE+n*AT_BLOCK_SIZE);
                    allocationTableRandomAccessFile.write(allocationBlock);
                }
                allocationTableRandomAccessFile.getFD().sync();
            }
            else
                log.debug("["+descriptor.getName()+"] Allocation table was not altered");
        }
        catch (IOException e)
        {
            throw new DataStoreException("Cannot check/fix store integrity : "+e);
        }
    }
14645
func (self *RotatingFileHandler) ShouldRollover(
	record *LogRecord) (bool, string) {

	message := self.Format(record)
	if self.maxBytes > 0 {
		offset, err := self.GetStream().Tell()
		if err != nil {
			// don't trigger rollover action if we lose offset info
			return false, message
		}
		if (uint64(offset) + uint64(len(message))) > self.maxBytes {
			return true, message
		}
	}
	return false, message
}
1132725
def _has_file_rolled(self):
        """"""
        # if the size is smaller then before, the file has
        # probabilly been rolled
        if self._fh:
            size = self._getsize_of_current_file()
            if size < self.oldsize:
                return True

            self.oldsize = size

        return False
727567
def emit(self, record):
        
        try:
            if self.shouldRollover(record):
                self.doRollover()
            FileHandler.emit(self, record)
        except (KeyboardInterrupt, SystemExit):
            raise
        except Exception:
            self.handleError(record)
873087
private void rolloverLogTask()
  {
    try {
      if (_isInit) {
        flush();
      }
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }

    _isRollingOver = true;
    
    try {
      if (! _isInit)
        return;
      
      Path savedPath = null;

      long now = CurrentTime.currentTime();

      long lastPeriodEnd = _nextPeriodEnd;

      _nextPeriodEnd = nextRolloverTime(now);

      Path path = getPath();

      synchronized (_logLock) {
        flushTempStream();

        long length = Files.size(path);
        
        if (lastPeriodEnd <= now && lastPeriodEnd > 0) {
          closeLogStream();

          savedPath = getSavedPath(lastPeriodEnd - 1);
        }
        else if (path != null && getRolloverSize() <= length) {
          closeLogStream();

          savedPath = getSavedPath(now);
        }
      }
      
      // archiving of path is outside of the synchronized block to
      // avoid freezing during archive
      if (savedPath != null) {
        movePathToArchive(savedPath);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      synchronized (_logLock) {
        _isRollingOver = false;
        flushTempStream();
      }
      
      _rolloverListener.requeue(_rolloverAlarm);
    }
  }
1003443
def doRollover(self):
        
        # Rotate the file first.
        handlers.RotatingFileHandler.doRollover(self)

        # Add group write to the current permissions.
        currMode = os.stat(self.baseFilename).st_mode
        os.chmod(self.baseFilename, currMode | stat.S_IWGRP |
                 stat.S_IRGRP | stat.S_IWOTH | stat.S_IROTH)
1140427
def _check(self): # TODO: fix?
        """"""
        if self._returncode:
            rarfile.check_returncode(self, '')
        if self._remain != 0:
            raise rarfile.BadRarFile("Failed the read enough data")
327275
private void afterRecord() {
        if (fileNamePattern != null && getRecordCounter() % splitlimit == 0) {
            try {
                endCollection();
                writer.close();
                newWriter(fileNamePattern, fileNameCounter, bufferSize, compress);
                setupEventConsumer(writer, indent);
                beginCollection();
            } catch (IOException e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
398550
def doRollover(self):
        """"""
        self.stream.close()
        try:
            if self.backupCount > 0:
                tmp_location = "%s.0" % self.baseFilename
                os.rename(self.baseFilename, tmp_location)
                for i in range(self.backupCount - 1, 0, -1):
                    sfn = "%s.%d" % (self.baseFilename, i)
                    dfn = "%s.%d" % (self.baseFilename, i + 1)
                    if os.path.exists(sfn):
                        if os.path.exists(dfn):
                            os.remove(dfn)
                        os.rename(sfn, dfn)
                dfn = self.baseFilename + ".1"
                if os.path.exists(dfn):
                    os.remove(dfn)
                os.rename(tmp_location, dfn)
        except Exception:
            pass
        finally:
            self.stream = WindowsFile(self.baseFilename, "a", self.encoding)
1333120
def is_rate_limit_exceeded(self):
        """"""
        history = self.get_history()
        if history.amount_api_calls >= settings.UNSHORTEN_DAILY_LIMIT:
            return True
        return False
538305
def content_size_exceeded_max(self, content_bytes):
        '''
        
        '''
        content_size = sys.getsizeof(content_bytes)
        if content_size > self.item_size_max():
            return (True, content_size)

        return (False, content_size)
1014396
def is_quota_exceeded(self) -> bool:
        ''''''

        if self.quota and self._url_table is not None:
            return self.size >= self.quota and \
                   self._url_table.get_root_url_todo_count() == 0
408949
void rollOver() throws IOException {

		// If compression is enabled we start a separated thread
		if (getCompressBackups().equalsIgnoreCase("YES")
				|| getCompressBackups().equalsIgnoreCase("TRUE")) {
			File file = new File(fileName);
			Thread fileCompressor = new Thread(new CompressFile(file));
			fileCompressor.start();
		}

		/* Compute filename, but only if datePattern is specified */
		if (datePattern == null) {
			errorHandler.error("Missing DatePattern option in rollOver().");
			return;
		}

		String datedFilename = baseFileName + sdf.format(now);
		// It is too early to roll over because we are still within the
		// bounds of the current interval. Rollover will occur once the
		// next interval is reached.
		if (scheduledFilename.equals(datedFilename)) {
			return;
		}

		activateOptions();
	}
1029186
def disk_check_size(ctx, param, value):
    
    if value:
        # if we've got a prefix
        if isinstance(value, tuple):
            val = value[1]
        else:
            val = value
        if val % 1024:
            raise click.ClickException('Size must be a multiple of 1024.')
    return value