func (f *Fs) AppendIfMissing(filePath string, content []byte, mode os.FileMode) error {
	exists, err := f.Exists(filePath)
	if err != nil {
		return errors.Wrapf(err, "could not confirm that file %s exists", filePath)
	}

	contentToWrite := append(content, []byte("\n")...)

	if !exists {
		err := f.WriteFile(filePath, contentToWrite, mode)
		if err != nil {
			return errors.Wrapf(err, "could not create file %s", filePath)
		}

		return nil
	}

	contains, err := f.FileContainsBytes(filePath, content)
	if err != nil {
		return errors.Wrapf(err, "could not check file %s for content", filePath)
	}

	if !contains {
		fileContents, err := f.ReadFile(filePath)
		if err != nil {
			return errors.Wrapf(err, "failed to read file %s", filePath)
		}

		newContents := append(fileContents, contentToWrite...)

		err = f.WriteFile(filePath, newContents, mode)
		if err != nil {
			return errors.Wrapf(err, "failed to append contents to file %s", filePath)
		}
	}

	return nil
}
// AppendIfMissing appends the content string to the given file.
AppendIfMissing appends the content string to the given file.
// AppendIfMissing appends the content string to the given file .
func (f *Fs) AppendIfMissing(filePath string, content []byte, mode os.FileMode) error {
	exists, err := f.Exists(filePath)
	if err != nil {
		return errors.Wrapf(err, "could not confirm that file %s exists", filePath)
	}
	contentToWrite := append(content, []byte("\n")...)
	if !exists {
		err := f.WriteFile(filePath, contentToWrite, mode)
		if err != nil {
			return errors.Wrapf(err, "could not create file %s", filePath)
		}
		return nil
	}
	contains, err := f.FileContainsBytes(filePath, content)
	if err != nil {
		return errors.Wrapf(err, "could not check file %s for content", filePath)
	}
	if !contains {
		fileContents, err := f.ReadFile(filePath)
		if err != nil {
			return errors.Wrapf(err, "failed to read file %s", filePath)
		}
		newContents := append(fileContents, contentToWrite...)
		err = f.WriteFile(filePath, newContents, mode)
		if err != nil {
			return errors.Wrapf(err, "failed to append contents to file %s", filePath)
		}
	}
	return nil
}
func ( f * Fs ) AppendIfMissing ( filePath string , content [ ] byte , mode os . FileMode ) error { exists , err := f . Exists ( filePath ) if err != nil { return errors . Wrapf ( err , " " , filePath ) } contentToWrite := append ( content , [ ] byte ( " \n " ) ... ) if ! exists { err := f . WriteFile ( filePath , contentToWrite , mode ) if err != nil { return errors . Wrapf ( err , " " , filePath ) } return nil } contains , err := f . FileContainsBytes ( filePath , content ) if err != nil { return errors . Wrapf ( err , " " , filePath ) } if ! contains { fileContents , err := f . ReadFile ( filePath ) if err != nil { return errors . Wrapf ( err , " " , filePath ) } newContents := append ( fileContents , contentToWrite ... ) err = f . WriteFile ( filePath , newContents , mode ) if err != nil { return errors . Wrapf ( err , " " , filePath ) } } return nil }
AppendIfMissing appends the content string to the given file.
AppendIfMissing appends the content string to the given file .