// Save implements the Save method of the eventhorizon.ReadRepo interface.
178714
func (r *Repo) Save(ctx context.Context, entity eh.Entity) error {
	r.SaveCalled = true
	if r.SaveErr != nil {
		return r.SaveErr
	}
	r.Entity = entity
	return nil
}
991070
func (m *Mem) Save(key models.Key, model models.Model) error {
	m.mut.Lock()
	defer m.mut.Unlock()
	m.m[key.String()] = model
	return nil
}
204214
func (m *GormRoleRepository) Save(ctx context.Context, model *Role) error {
	defer goa.MeasureSince([]string{"goa", "db", "role", "save"}, time.Now())

	obj, err := m.Load(ctx, model.RoleID)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"role_id": model.RoleID,
			"err":     err,
		}, "unable to update role")
		return errs.WithStack(err)
	}
	err = m.db.Model(obj).Updates(model).Error
	if err != nil {
		if gormsupport.IsUniqueViolation(err, "uq_role_resource_type_name") {
			log.Error(ctx, map[string]interface{}{
				"err":              err,
				"role_name":        model.Name,
				"resource_type_id": model.ResourceTypeID,
			}, "unable to create role because the same role already exists for this resource_type")
			return errors.NewDataConflictError(fmt.Sprintf("role already exists with name = %s , resource_type_id = %s ", model.Name, model.ResourceTypeID.String()))
		}
		return errs.WithStack(err)
	}

	log.Debug(ctx, map[string]interface{}{
		"role_id": model.RoleID,
	}, "Role saved!")
	return nil
}
131528
func Save(path string, v interface{}) error {
	lock.Lock()
	defer lock.Unlock()
	f, err := os.Create(path)
	if err != nil {
		return err
	}
	defer f.Close()
	r, err := Marshal(v)
	if err != nil {
		return err
	}
	_, err = io.Copy(f, r)
	return err
}
1120211
func (f *File) Save(name string) error {
	return ioutil.WriteFile(name, f.Data(), 0666)
}
824605
func (f *File) Save(name string) error {
	return ioutil.WriteFile(name, []byte(f.String()), 0666)
}
272032
func (r *Repo) Save(ctx context.Context, entity eh.Entity) error {
	// Bust the cache on save.
	ns := r.namespace(ctx)
	r.cacheMu.Lock()
	delete(r.cache[ns], entity.EntityID())
	r.cacheMu.Unlock()

	return r.ReadWriteRepo.Save(ctx, entity)
}
1867
func (api *API) Save(metadata params.MetadataSaveParams) (params.ErrorResults, error) {
	all, err := imagecommon.Save(api.metadata, metadata)
	if err != nil {
		return params.ErrorResults{}, errors.Trace(err)
	}
	return params.ErrorResults{Results: all}, nil
}
1275199
func (clientSettings *ClientSettings) Save() error {
	req, err := client.NewJSONRequest(
		Config,
		"PUT",
		"/papi/v1/client-settings",
		clientSettings,
	)
	if err != nil {
		return err
	}

	res, err := client.Do(Config, req)
	if err != nil {
		return err
	}

	if client.IsError(res) {
		return client.NewAPIError(res)
	}

	newClientSettings := NewClientSettings()
	if err := client.BodyJSON(res, newClientSettings); err != nil {
		return err
	}

	clientSettings.RuleFormat = newClientSettings.RuleFormat

	return nil
}
345447
func Save(path string, data interface{}) error {
	err := os.MkdirAll(filepath.Dir(path), os.ModeDir+0666)
	if err != nil {
		return err
	}
	file, err := os.Create(path)
	if err != nil {
		return err
	}
	defer file.Close()
	buf, err := json.MarshalIndent(data, "", "    ")
	if err != nil {
		return err
	}
	_, err = io.Copy(file, bytes.NewReader(buf))
	return err
}
382440
func (st *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
	s, _ := context.Get(r, contextKey(session.Name())).(*gormSession)

	// delete if max age is < 0
	if session.Options.MaxAge < 0 {
		if s != nil {
			if err := st.db.Delete(s).Error; err != nil {
				return err
			}
		}
		http.SetCookie(w, sessions.NewCookie(session.Name(), "", session.Options))
		return nil
	}

	data, err := securecookie.EncodeMulti(session.Name(), session.Values, st.Codecs...)
	if err != nil {
		return err
	}
	now := time.Now()
	expire := now.Add(time.Second * time.Duration(session.Options.MaxAge))

	if s == nil {
		// generate random session ID key suitable for storage in the db
		session.ID = strings.TrimRight(
			base32.StdEncoding.EncodeToString(
				securecookie.GenerateRandomKey(sessionIDLen)), "=")
		s = &gormSession{
			ID:        session.ID,
			Data:      data,
			CreatedAt: now,
			UpdatedAt: now,
			ExpiresAt: expire,
			tableName: st.opts.TableName,
		}
		if err := st.db.Create(s).Error; err != nil {
			return err
		}
		context.Set(r, contextKey(session.Name()), s)
	} else {
		s.Data = data
		s.UpdatedAt = now
		s.ExpiresAt = expire
		if err := st.db.Save(s).Error; err != nil {
			return err
		}
	}

	// set session id cookie
	id, err := securecookie.EncodeMulti(session.Name(), session.ID, st.Codecs...)
	if err != nil {
		return err
	}
	http.SetCookie(w, sessions.NewCookie(session.Name(), id, session.Options))

	return nil
}
204992
func (m *MockStorage) Save(ctx context.Context, object *jsh.Object) (*jsh.Object, jsh.ErrorType) {
	var err *jsh.Error
	object.ID = "1"

	return object, err
}
1122870
func (j *Job) save() error {
	t := newTransaction()
	t.saveJob(j)
	if err := t.exec(); err != nil {
		return err
	}
	return nil
}
1118814
func (h *history) Save() (err error) {
	if _, err = h.file.Seek(0, 0); err != nil {
		return
	}

	out := bufio.NewWriter(h.file)
	element := h.li.Front() // Get the first element.

	for i := 0; i < h.li.Len(); i++ {
		line := element.Value.(string)

		if strings.HasPrefix(line, " ") {
			goto _next
		}
		if line = strings.TrimSpace(line); line == "" {
			goto _next
		}
		if _, err = out.WriteString(line + "\n"); err != nil {
			log.Println("history.Save:", err)
			break
		}

	_next:
		if element = element.Next(); element == nil {
			continue
		}
	}

	if err = out.Flush(); err != nil {
		log.Println("history.Save:", err)
	}

	h.close()
	return
}
450930
func (s *S3Storage) Save(path string, file File) error {
	return s.SaveWithContentType(path, file, mime.TypeByExtension(filepath.Ext(path)))
}
889899
func (c Config) Save(file string) error {
	var s = fileOutput(c.root)
	return ioutil.WriteFile(file, []byte(s), 0666)
}
80184
func (p *Pubring) Save() error {
	buf, err := proto.Marshal(p.data)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(p.File, buf, 0600)
}