func (m *v1beta1Migrator) writeV1Config(
	configPath string,
	config bufconfig.ExternalConfigV1,
	originalRootName string,
	originalModuleName string,
) (retErr error) {
	v1ConfigData, err := encoding.MarshalYAML(&config)
	if err != nil {
		return fmt.Errorf("failed to marshal new config: %w", err)
	}
	header := fmt.Sprintf(bufModHeaderWithName, m.commandName, originalRootName, originalModuleName)
	if originalModuleName == "" {
		header = fmt.Sprintf(bufModHeaderWithoutName, m.commandName, originalRootName)
	}
	v1ConfigData = append([]byte(header), v1ConfigData...)
	if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
		// This happens if the user has a root specified that doesn't have a corresponding
		// directory on the filesystem.
		return fmt.Errorf("failed to create new directories for writing config: %w", err)
	}
	return os.WriteFile(configPath, v1ConfigData, 0600)
}
// writeV1Config atomically replaces the old configuration file by first writing
// the new config to a temporary file and then moving it to the old config file path.
// If we fail to marshal or write, the old config file is not touched.
writeV1Config atomically replaces the old configuration file by first writing
the new config to a temporary file and then moving it to the old config file path.
If we fail to marshal or write, the old config file is not touched.
// writeV1Config atomically replaces the old configuration file by first writing // the new config to a temporary file and then moving it to the old config file path . // If we fail to marshal or write the old config file is not touched .
func (m *v1beta1Migrator) writeV1Config(
	configPath string,
	config bufconfig.ExternalConfigV1,
	originalRootName string,
	originalModuleName string,
) (retErr error) {
	v1ConfigData, err := encoding.MarshalYAML(&config)
	if err != nil {
		return fmt.Errorf("failed to marshal new config: %w", err)
	}
	header := fmt.Sprintf(bufModHeaderWithName, m.commandName, originalRootName, originalModuleName)
	if originalModuleName == "" {
		header = fmt.Sprintf(bufModHeaderWithoutName, m.commandName, originalRootName)
	}
	v1ConfigData = append([]byte(header), v1ConfigData...)
	if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
		return fmt.Errorf("failed to create new directories for writing config: %w", err)
	}
	return os.WriteFile(configPath, v1ConfigData, 0600)
}
func ( m * v1beta1Migrator ) writeV1Config ( configPath string , config bufconfig . ExternalConfigV1 , originalRootName string , originalModuleName string , ) ( retErr error ) { v1ConfigData , err := encoding . MarshalYAML ( & config ) if err != nil { return fmt . Errorf ( " " , err ) } header := fmt . Sprintf ( bufModHeaderWithName , m . commandName , originalRootName , originalModuleName ) if originalModuleName == " " { header = fmt . Sprintf ( bufModHeaderWithoutName , m . commandName , originalRootName ) } v1ConfigData = append ( [ ] byte ( header ) , v1ConfigData ... ) if err := os . MkdirAll ( filepath . Dir ( configPath ) , 0755 ) ; err != nil { return fmt . Errorf ( " " , err ) } return os . WriteFile ( configPath , v1ConfigData , 0600 ) }
writeV1Config atomically replaces the old configuration file by first writing
the new config to a temporary file and then moving it to the old config file path.
writeV1Config atomically replaces the old configuration file by first writing the new config to a temporary file and then moving it to the old config file path .
// This happens if the user has a root specified that doesn't have a corresponding // directory on the filesystem.