file/io.go
func Backup(filename string) error {
	// Check if it is empty
	info, err := os.Stat(filename)
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		return err
	}
	if info.Size() == 0 {
		return nil
	}

	files, err := filepath.Glob(filename + _BACKUP_SUFFIX)
	if err != nil {
		return err
	}

	// Number rotation
	numBackup := byte(1)

	if len(files) != 0 {
		lastFile := files[len(files)-1]
		numBackup = lastFile[len(lastFile)-2] + 1 // next number

		if numBackup > '9' {
			numBackup = '1'
		}
	} else {
		numBackup = '1'
	}

	return Copy(filename, fmt.Sprintf("%s+%s~", filename, string(numBackup)))
}
func Backup(filename string) error {
	// Check if it is empty
	info, err := os.Stat(filename)
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		return err
	}
	if info.Size() == 0 {
		return nil
	}

	files, err := filepath.Glob(filename + _BACKUP_SUFFIX)
	if err != nil {
		return err
	}

	// Number rotation
	numBackup := byte(1)

	if len(files) != 0 {
		lastFile := files[len(files)-1]
		numBackup = lastFile[len(lastFile)-2] + 1 // next number

		if numBackup > '9' {
			numBackup = '1'
		}
	} else {
		numBackup = '1'
	}

	return Copy(filename, fmt.Sprintf("%s+%s~", filename, string(numBackup)))
}
func Backup ( filename string ) error { // Check if it is empty info , err := os . Stat ( filename ) if err != nil { if os . IsNotExist ( err ) { return nil } return err } if info . Size ( ) == 0 { return nil } files , err := filepath . Glob ( filename + _BACKUP_SUFFIX ) if err != nil { return err } // Number rotation numBackup := byte ( 1 ) if len ( files ) != 0 { lastFile := files [ len ( files ) - 1 ] numBackup = lastFile [ len ( lastFile ) - 2 ] + 1 // next number if numBackup > '9' { numBackup = '1' } } else { numBackup = '1' } return Copy ( filename , fmt . Sprintf ( " " , filename , string ( numBackup ) ) ) }
// Backup creates a backup of the named file.
//
// The schema used for the new name is: {name}\+[1-9]~
//   name: The original file name.
//   + : Character used to separate the file name from rest.
//   number: A number from 1 to 9, using rotation.
//   ~ : To indicate that it is a backup, just like it is used in Unix systems.
Backup creates a backup of the named file . The schema used for the new name is : { name } \ + [ 1 - 9 ] ~ name : The original file name . + : Character used to separate the file name from rest . number : A number from 1 to 9 using rotation . ~ : To indicate that it is a backup just like it is used in Unix systems .