// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/cloudreve/Cloudreve/v4/ent/directlink"
	"github.com/cloudreve/Cloudreve/v4/ent/entity"
	"github.com/cloudreve/Cloudreve/v4/ent/file"
	"github.com/cloudreve/Cloudreve/v4/ent/metadata"
	"github.com/cloudreve/Cloudreve/v4/ent/predicate"
	"github.com/cloudreve/Cloudreve/v4/ent/share"
	"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
	"github.com/cloudreve/Cloudreve/v4/ent/user"
	"github.com/cloudreve/Cloudreve/v4/inventory/types"
)

// FileUpdate is the builder for updating File entities.
type FileUpdate struct {
	config
	hooks    []Hook
	mutation *FileMutation
}

// Where appends a list predicates to the FileUpdate builder.
func (fu *FileUpdate) Where(ps ...predicate.File) *FileUpdate {
	fu.mutation.Where(ps...)
	return fu
}

// SetUpdatedAt sets the "updated_at" field.
func (fu *FileUpdate) SetUpdatedAt(t time.Time) *FileUpdate {
	fu.mutation.SetUpdatedAt(t)
	return fu
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (fu *FileUpdate) SetNillableUpdatedAt(t *time.Time) *FileUpdate {
	if t != nil {
		fu.SetUpdatedAt(*t)
	}
	return fu
}

// SetType sets the "type" field.
func (fu *FileUpdate) SetType(i int) *FileUpdate {
	fu.mutation.ResetType()
	fu.mutation.SetType(i)
	return fu
}

// SetNillableType sets the "type" field if the given value is not nil.
func (fu *FileUpdate) SetNillableType(i *int) *FileUpdate {
	if i != nil {
		fu.SetType(*i)
	}
	return fu
}

// AddType adds i to the "type" field.
func (fu *FileUpdate) AddType(i int) *FileUpdate {
	fu.mutation.AddType(i)
	return fu
}

// SetName sets the "name" field.
func (fu *FileUpdate) SetName(s string) *FileUpdate {
	fu.mutation.SetName(s)
	return fu
}

// SetNillableName sets the "name" field if the given value is not nil.
func (fu *FileUpdate) SetNillableName(s *string) *FileUpdate {
	if s != nil {
		fu.SetName(*s)
	}
	return fu
}

// SetOwnerID sets the "owner_id" field.
func (fu *FileUpdate) SetOwnerID(i int) *FileUpdate {
	fu.mutation.SetOwnerID(i)
	return fu
}

// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
func (fu *FileUpdate) SetNillableOwnerID(i *int) *FileUpdate {
	if i != nil {
		fu.SetOwnerID(*i)
	}
	return fu
}

// SetSize sets the "size" field.
func (fu *FileUpdate) SetSize(i int64) *FileUpdate {
	fu.mutation.ResetSize()
	fu.mutation.SetSize(i)
	return fu
}

// SetNillableSize sets the "size" field if the given value is not nil.
func (fu *FileUpdate) SetNillableSize(i *int64) *FileUpdate {
	if i != nil {
		fu.SetSize(*i)
	}
	return fu
}

// AddSize adds i to the "size" field.
func (fu *FileUpdate) AddSize(i int64) *FileUpdate {
	fu.mutation.AddSize(i)
	return fu
}

// SetPrimaryEntity sets the "primary_entity" field.
func (fu *FileUpdate) SetPrimaryEntity(i int) *FileUpdate {
	fu.mutation.ResetPrimaryEntity()
	fu.mutation.SetPrimaryEntity(i)
	return fu
}

// SetNillablePrimaryEntity sets the "primary_entity" field if the given value is not nil.
func (fu *FileUpdate) SetNillablePrimaryEntity(i *int) *FileUpdate {
	if i != nil {
		fu.SetPrimaryEntity(*i)
	}
	return fu
}

// AddPrimaryEntity adds i to the "primary_entity" field.
func (fu *FileUpdate) AddPrimaryEntity(i int) *FileUpdate {
	fu.mutation.AddPrimaryEntity(i)
	return fu
}

// ClearPrimaryEntity clears the value of the "primary_entity" field.
func (fu *FileUpdate) ClearPrimaryEntity() *FileUpdate {
	fu.mutation.ClearPrimaryEntity()
	return fu
}

// SetFileChildren sets the "file_children" field.
func (fu *FileUpdate) SetFileChildren(i int) *FileUpdate {
	fu.mutation.SetFileChildren(i)
	return fu
}

// SetNillableFileChildren sets the "file_children" field if the given value is not nil.
func (fu *FileUpdate) SetNillableFileChildren(i *int) *FileUpdate {
	if i != nil {
		fu.SetFileChildren(*i)
	}
	return fu
}

// ClearFileChildren clears the value of the "file_children" field.
func (fu *FileUpdate) ClearFileChildren() *FileUpdate {
	fu.mutation.ClearFileChildren()
	return fu
}

// SetIsSymbolic sets the "is_symbolic" field.
func (fu *FileUpdate) SetIsSymbolic(b bool) *FileUpdate {
	fu.mutation.SetIsSymbolic(b)
	return fu
}

// SetNillableIsSymbolic sets the "is_symbolic" field if the given value is not nil.
func (fu *FileUpdate) SetNillableIsSymbolic(b *bool) *FileUpdate {
	if b != nil {
		fu.SetIsSymbolic(*b)
	}
	return fu
}

// SetProps sets the "props" field.
func (fu *FileUpdate) SetProps(tp *types.FileProps) *FileUpdate {
	fu.mutation.SetProps(tp)
	return fu
}

// ClearProps clears the value of the "props" field.
func (fu *FileUpdate) ClearProps() *FileUpdate {
	fu.mutation.ClearProps()
	return fu
}

// SetStoragePolicyFiles sets the "storage_policy_files" field.
func (fu *FileUpdate) SetStoragePolicyFiles(i int) *FileUpdate {
	fu.mutation.SetStoragePolicyFiles(i)
	return fu
}

// SetNillableStoragePolicyFiles sets the "storage_policy_files" field if the given value is not nil.
func (fu *FileUpdate) SetNillableStoragePolicyFiles(i *int) *FileUpdate {
	if i != nil {
		fu.SetStoragePolicyFiles(*i)
	}
	return fu
}

// ClearStoragePolicyFiles clears the value of the "storage_policy_files" field.
func (fu *FileUpdate) ClearStoragePolicyFiles() *FileUpdate {
	fu.mutation.ClearStoragePolicyFiles()
	return fu
}

// SetOwner sets the "owner" edge to the User entity.
func (fu *FileUpdate) SetOwner(u *User) *FileUpdate {
	return fu.SetOwnerID(u.ID)
}

// SetStoragePoliciesID sets the "storage_policies" edge to the StoragePolicy entity by ID.
func (fu *FileUpdate) SetStoragePoliciesID(id int) *FileUpdate {
	fu.mutation.SetStoragePoliciesID(id)
	return fu
}

// SetNillableStoragePoliciesID sets the "storage_policies" edge to the StoragePolicy entity by ID if the given value is not nil.
func (fu *FileUpdate) SetNillableStoragePoliciesID(id *int) *FileUpdate {
	if id != nil {
		fu = fu.SetStoragePoliciesID(*id)
	}
	return fu
}

// SetStoragePolicies sets the "storage_policies" edge to the StoragePolicy entity.
func (fu *FileUpdate) SetStoragePolicies(s *StoragePolicy) *FileUpdate {
	return fu.SetStoragePoliciesID(s.ID)
}

// SetParentID sets the "parent" edge to the File entity by ID.
func (fu *FileUpdate) SetParentID(id int) *FileUpdate {
	fu.mutation.SetParentID(id)
	return fu
}

// SetNillableParentID sets the "parent" edge to the File entity by ID if the given value is not nil.
func (fu *FileUpdate) SetNillableParentID(id *int) *FileUpdate {
	if id != nil {
		fu = fu.SetParentID(*id)
	}
	return fu
}

// SetParent sets the "parent" edge to the File entity.
func (fu *FileUpdate) SetParent(f *File) *FileUpdate {
	return fu.SetParentID(f.ID)
}

// AddChildIDs adds the "children" edge to the File entity by IDs.
func (fu *FileUpdate) AddChildIDs(ids ...int) *FileUpdate {
	fu.mutation.AddChildIDs(ids...)
	return fu
}

// AddChildren adds the "children" edges to the File entity.
func (fu *FileUpdate) AddChildren(f ...*File) *FileUpdate {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return fu.AddChildIDs(ids...)
}

// AddMetadatumIDs adds the "metadata" edge to the Metadata entity by IDs.
func (fu *FileUpdate) AddMetadatumIDs(ids ...int) *FileUpdate {
	fu.mutation.AddMetadatumIDs(ids...)
	return fu
}

// AddMetadata adds the "metadata" edges to the Metadata entity.
func (fu *FileUpdate) AddMetadata(m ...*Metadata) *FileUpdate {
	ids := make([]int, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return fu.AddMetadatumIDs(ids...)
}

// AddEntityIDs adds the "entities" edge to the Entity entity by IDs.
func (fu *FileUpdate) AddEntityIDs(ids ...int) *FileUpdate {
	fu.mutation.AddEntityIDs(ids...)
	return fu
}

// AddEntities adds the "entities" edges to the Entity entity.
func (fu *FileUpdate) AddEntities(e ...*Entity) *FileUpdate {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return fu.AddEntityIDs(ids...)
}

// AddShareIDs adds the "shares" edge to the Share entity by IDs.
func (fu *FileUpdate) AddShareIDs(ids ...int) *FileUpdate {
	fu.mutation.AddShareIDs(ids...)
	return fu
}

// AddShares adds the "shares" edges to the Share entity.
func (fu *FileUpdate) AddShares(s ...*Share) *FileUpdate {
	ids := make([]int, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return fu.AddShareIDs(ids...)
}

// AddDirectLinkIDs adds the "direct_links" edge to the DirectLink entity by IDs.
func (fu *FileUpdate) AddDirectLinkIDs(ids ...int) *FileUpdate {
	fu.mutation.AddDirectLinkIDs(ids...)
	return fu
}

// AddDirectLinks adds the "direct_links" edges to the DirectLink entity.
func (fu *FileUpdate) AddDirectLinks(d ...*DirectLink) *FileUpdate {
	ids := make([]int, len(d))
	for i := range d {
		ids[i] = d[i].ID
	}
	return fu.AddDirectLinkIDs(ids...)
}

// Mutation returns the FileMutation object of the builder.
func (fu *FileUpdate) Mutation() *FileMutation {
	return fu.mutation
}

// ClearOwner clears the "owner" edge to the User entity.
func (fu *FileUpdate) ClearOwner() *FileUpdate {
	fu.mutation.ClearOwner()
	return fu
}

// ClearStoragePolicies clears the "storage_policies" edge to the StoragePolicy entity.
func (fu *FileUpdate) ClearStoragePolicies() *FileUpdate {
	fu.mutation.ClearStoragePolicies()
	return fu
}

// ClearParent clears the "parent" edge to the File entity.
func (fu *FileUpdate) ClearParent() *FileUpdate {
	fu.mutation.ClearParent()
	return fu
}

// ClearChildren clears all "children" edges to the File entity.
func (fu *FileUpdate) ClearChildren() *FileUpdate {
	fu.mutation.ClearChildren()
	return fu
}

// RemoveChildIDs removes the "children" edge to File entities by IDs.
func (fu *FileUpdate) RemoveChildIDs(ids ...int) *FileUpdate {
	fu.mutation.RemoveChildIDs(ids...)
	return fu
}

// RemoveChildren removes "children" edges to File entities.
func (fu *FileUpdate) RemoveChildren(f ...*File) *FileUpdate {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return fu.RemoveChildIDs(ids...)
}

// ClearMetadata clears all "metadata" edges to the Metadata entity.
func (fu *FileUpdate) ClearMetadata() *FileUpdate {
	fu.mutation.ClearMetadata()
	return fu
}

// RemoveMetadatumIDs removes the "metadata" edge to Metadata entities by IDs.
func (fu *FileUpdate) RemoveMetadatumIDs(ids ...int) *FileUpdate {
	fu.mutation.RemoveMetadatumIDs(ids...)
	return fu
}

// RemoveMetadata removes "metadata" edges to Metadata entities.
func (fu *FileUpdate) RemoveMetadata(m ...*Metadata) *FileUpdate {
	ids := make([]int, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return fu.RemoveMetadatumIDs(ids...)
}

// ClearEntities clears all "entities" edges to the Entity entity.
func (fu *FileUpdate) ClearEntities() *FileUpdate {
	fu.mutation.ClearEntities()
	return fu
}

// RemoveEntityIDs removes the "entities" edge to Entity entities by IDs.
func (fu *FileUpdate) RemoveEntityIDs(ids ...int) *FileUpdate {
	fu.mutation.RemoveEntityIDs(ids...)
	return fu
}

// RemoveEntities removes "entities" edges to Entity entities.
func (fu *FileUpdate) RemoveEntities(e ...*Entity) *FileUpdate {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return fu.RemoveEntityIDs(ids...)
}

// ClearShares clears all "shares" edges to the Share entity.
func (fu *FileUpdate) ClearShares() *FileUpdate {
	fu.mutation.ClearShares()
	return fu
}

// RemoveShareIDs removes the "shares" edge to Share entities by IDs.
func (fu *FileUpdate) RemoveShareIDs(ids ...int) *FileUpdate {
	fu.mutation.RemoveShareIDs(ids...)
	return fu
}

// RemoveShares removes "shares" edges to Share entities.
func (fu *FileUpdate) RemoveShares(s ...*Share) *FileUpdate {
	ids := make([]int, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return fu.RemoveShareIDs(ids...)
}

// ClearDirectLinks clears all "direct_links" edges to the DirectLink entity.
func (fu *FileUpdate) ClearDirectLinks() *FileUpdate {
	fu.mutation.ClearDirectLinks()
	return fu
}

// RemoveDirectLinkIDs removes the "direct_links" edge to DirectLink entities by IDs.
func (fu *FileUpdate) RemoveDirectLinkIDs(ids ...int) *FileUpdate {
	fu.mutation.RemoveDirectLinkIDs(ids...)
	return fu
}

// RemoveDirectLinks removes "direct_links" edges to DirectLink entities.
func (fu *FileUpdate) RemoveDirectLinks(d ...*DirectLink) *FileUpdate {
	ids := make([]int, len(d))
	for i := range d {
		ids[i] = d[i].ID
	}
	return fu.RemoveDirectLinkIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (fu *FileUpdate) SaveX(ctx context.Context) int {
	affected, err := fu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (fu *FileUpdate) Exec(ctx context.Context) error {
	_, err := fu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (fu *FileUpdate) ExecX(ctx context.Context) {
	if err := fu.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (fu *FileUpdate) check() error {
	if _, ok := fu.mutation.OwnerID(); fu.mutation.OwnerCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "File.owner"`)
	}
	return nil
}

func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := fu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt))
	if ps := fu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := fu.mutation.UpdatedAt(); ok {
		_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := fu.mutation.GetType(); ok {
		_spec.SetField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := fu.mutation.AddedType(); ok {
		_spec.AddField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := fu.mutation.Name(); ok {
		_spec.SetField(file.FieldName, field.TypeString, value)
	}
	if value, ok := fu.mutation.Size(); ok {
		_spec.SetField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := fu.mutation.AddedSize(); ok {
		_spec.AddField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := fu.mutation.PrimaryEntity(); ok {
		_spec.SetField(file.FieldPrimaryEntity, field.TypeInt, value)
	}
	if value, ok := fu.mutation.AddedPrimaryEntity(); ok {
		_spec.AddField(file.FieldPrimaryEntity, field.TypeInt, value)
	}
	if fu.mutation.PrimaryEntityCleared() {
		_spec.ClearField(file.FieldPrimaryEntity, field.TypeInt)
	}
	if value, ok := fu.mutation.IsSymbolic(); ok {
		_spec.SetField(file.FieldIsSymbolic, field.TypeBool, value)
	}
	if value, ok := fu.mutation.Props(); ok {
		_spec.SetField(file.FieldProps, field.TypeJSON, value)
	}
	if fu.mutation.PropsCleared() {
		_spec.ClearField(file.FieldProps, field.TypeJSON)
	}
	if fu.mutation.OwnerCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.OwnerIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.StoragePoliciesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.StoragePoliciesTable,
			Columns: []string{file.StoragePoliciesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.StoragePoliciesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.StoragePoliciesTable,
			Columns: []string{file.StoragePoliciesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !fu.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RemovedMetadataIDs(); len(nodes) > 0 && !fu.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.MetadataIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   file.EntitiesTable,
			Columns: file.EntitiesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RemovedEntitiesIDs(); len(nodes) > 0 && !fu.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   file.EntitiesTable,
			Columns: file.EntitiesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.EntitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   file.EntitiesTable,
			Columns: file.EntitiesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.SharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.SharesTable,
			Columns: []string{file.SharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RemovedSharesIDs(); len(nodes) > 0 && !fu.mutation.SharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.SharesTable,
			Columns: []string{file.SharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.SharesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.SharesTable,
			Columns: []string{file.SharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.DirectLinksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.DirectLinksTable,
			Columns: []string{file.DirectLinksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RemovedDirectLinksIDs(); len(nodes) > 0 && !fu.mutation.DirectLinksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.DirectLinksTable,
			Columns: []string{file.DirectLinksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.DirectLinksIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.DirectLinksTable,
			Columns: []string{file.DirectLinksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, fu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{file.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	fu.mutation.done = true
	return n, nil
}

// FileUpdateOne is the builder for updating a single File entity.
type FileUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *FileMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (fuo *FileUpdateOne) SetUpdatedAt(t time.Time) *FileUpdateOne {
	fuo.mutation.SetUpdatedAt(t)
	return fuo
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableUpdatedAt(t *time.Time) *FileUpdateOne {
	if t != nil {
		fuo.SetUpdatedAt(*t)
	}
	return fuo
}

// SetType sets the "type" field.
func (fuo *FileUpdateOne) SetType(i int) *FileUpdateOne {
	fuo.mutation.ResetType()
	fuo.mutation.SetType(i)
	return fuo
}

// SetNillableType sets the "type" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableType(i *int) *FileUpdateOne {
	if i != nil {
		fuo.SetType(*i)
	}
	return fuo
}

// AddType adds i to the "type" field.
func (fuo *FileUpdateOne) AddType(i int) *FileUpdateOne {
	fuo.mutation.AddType(i)
	return fuo
}

// SetName sets the "name" field.
func (fuo *FileUpdateOne) SetName(s string) *FileUpdateOne {
	fuo.mutation.SetName(s)
	return fuo
}

// SetNillableName sets the "name" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableName(s *string) *FileUpdateOne {
	if s != nil {
		fuo.SetName(*s)
	}
	return fuo
}

// SetOwnerID sets the "owner_id" field.
func (fuo *FileUpdateOne) SetOwnerID(i int) *FileUpdateOne {
	fuo.mutation.SetOwnerID(i)
	return fuo
}

// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableOwnerID(i *int) *FileUpdateOne {
	if i != nil {
		fuo.SetOwnerID(*i)
	}
	return fuo
}

// SetSize sets the "size" field.
func (fuo *FileUpdateOne) SetSize(i int64) *FileUpdateOne {
	fuo.mutation.ResetSize()
	fuo.mutation.SetSize(i)
	return fuo
}

// SetNillableSize sets the "size" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableSize(i *int64) *FileUpdateOne {
	if i != nil {
		fuo.SetSize(*i)
	}
	return fuo
}

// AddSize adds i to the "size" field.
func (fuo *FileUpdateOne) AddSize(i int64) *FileUpdateOne {
	fuo.mutation.AddSize(i)
	return fuo
}

// SetPrimaryEntity sets the "primary_entity" field.
func (fuo *FileUpdateOne) SetPrimaryEntity(i int) *FileUpdateOne {
	fuo.mutation.ResetPrimaryEntity()
	fuo.mutation.SetPrimaryEntity(i)
	return fuo
}

// SetNillablePrimaryEntity sets the "primary_entity" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillablePrimaryEntity(i *int) *FileUpdateOne {
	if i != nil {
		fuo.SetPrimaryEntity(*i)
	}
	return fuo
}

// AddPrimaryEntity adds i to the "primary_entity" field.
func (fuo *FileUpdateOne) AddPrimaryEntity(i int) *FileUpdateOne {
	fuo.mutation.AddPrimaryEntity(i)
	return fuo
}

// ClearPrimaryEntity clears the value of the "primary_entity" field.
func (fuo *FileUpdateOne) ClearPrimaryEntity() *FileUpdateOne {
	fuo.mutation.ClearPrimaryEntity()
	return fuo
}

// SetFileChildren sets the "file_children" field.
func (fuo *FileUpdateOne) SetFileChildren(i int) *FileUpdateOne {
	fuo.mutation.SetFileChildren(i)
	return fuo
}

// SetNillableFileChildren sets the "file_children" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableFileChildren(i *int) *FileUpdateOne {
	if i != nil {
		fuo.SetFileChildren(*i)
	}
	return fuo
}

// ClearFileChildren clears the value of the "file_children" field.
func (fuo *FileUpdateOne) ClearFileChildren() *FileUpdateOne {
	fuo.mutation.ClearFileChildren()
	return fuo
}

// SetIsSymbolic sets the "is_symbolic" field.
func (fuo *FileUpdateOne) SetIsSymbolic(b bool) *FileUpdateOne {
	fuo.mutation.SetIsSymbolic(b)
	return fuo
}

// SetNillableIsSymbolic sets the "is_symbolic" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableIsSymbolic(b *bool) *FileUpdateOne {
	if b != nil {
		fuo.SetIsSymbolic(*b)
	}
	return fuo
}

// SetProps sets the "props" field.
func (fuo *FileUpdateOne) SetProps(tp *types.FileProps) *FileUpdateOne {
	fuo.mutation.SetProps(tp)
	return fuo
}

// ClearProps clears the value of the "props" field.
func (fuo *FileUpdateOne) ClearProps() *FileUpdateOne {
	fuo.mutation.ClearProps()
	return fuo
}

// SetStoragePolicyFiles sets the "storage_policy_files" field.
func (fuo *FileUpdateOne) SetStoragePolicyFiles(i int) *FileUpdateOne {
	fuo.mutation.SetStoragePolicyFiles(i)
	return fuo
}

// SetNillableStoragePolicyFiles sets the "storage_policy_files" field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableStoragePolicyFiles(i *int) *FileUpdateOne {
	if i != nil {
		fuo.SetStoragePolicyFiles(*i)
	}
	return fuo
}

// ClearStoragePolicyFiles clears the value of the "storage_policy_files" field.
func (fuo *FileUpdateOne) ClearStoragePolicyFiles() *FileUpdateOne {
	fuo.mutation.ClearStoragePolicyFiles()
	return fuo
}

// SetOwner sets the "owner" edge to the User entity.
func (fuo *FileUpdateOne) SetOwner(u *User) *FileUpdateOne {
	return fuo.SetOwnerID(u.ID)
}

// SetStoragePoliciesID sets the "storage_policies" edge to the StoragePolicy entity by ID.
func (fuo *FileUpdateOne) SetStoragePoliciesID(id int) *FileUpdateOne {
	fuo.mutation.SetStoragePoliciesID(id)
	return fuo
}

// SetNillableStoragePoliciesID sets the "storage_policies" edge to the StoragePolicy entity by ID if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableStoragePoliciesID(id *int) *FileUpdateOne {
	if id != nil {
		fuo = fuo.SetStoragePoliciesID(*id)
	}
	return fuo
}

// SetStoragePolicies sets the "storage_policies" edge to the StoragePolicy entity.
func (fuo *FileUpdateOne) SetStoragePolicies(s *StoragePolicy) *FileUpdateOne {
	return fuo.SetStoragePoliciesID(s.ID)
}

// SetParentID sets the "parent" edge to the File entity by ID.
func (fuo *FileUpdateOne) SetParentID(id int) *FileUpdateOne {
	fuo.mutation.SetParentID(id)
	return fuo
}

// SetNillableParentID sets the "parent" edge to the File entity by ID if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableParentID(id *int) *FileUpdateOne {
	if id != nil {
		fuo = fuo.SetParentID(*id)
	}
	return fuo
}

// SetParent sets the "parent" edge to the File entity.
func (fuo *FileUpdateOne) SetParent(f *File) *FileUpdateOne {
	return fuo.SetParentID(f.ID)
}

// AddChildIDs adds the "children" edge to the File entity by IDs.
func (fuo *FileUpdateOne) AddChildIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.AddChildIDs(ids...)
	return fuo
}

// AddChildren adds the "children" edges to the File entity.
func (fuo *FileUpdateOne) AddChildren(f ...*File) *FileUpdateOne {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return fuo.AddChildIDs(ids...)
}

// AddMetadatumIDs adds the "metadata" edge to the Metadata entity by IDs.
func (fuo *FileUpdateOne) AddMetadatumIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.AddMetadatumIDs(ids...)
	return fuo
}

// AddMetadata adds the "metadata" edges to the Metadata entity.
func (fuo *FileUpdateOne) AddMetadata(m ...*Metadata) *FileUpdateOne {
	ids := make([]int, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return fuo.AddMetadatumIDs(ids...)
}

// AddEntityIDs adds the "entities" edge to the Entity entity by IDs.
func (fuo *FileUpdateOne) AddEntityIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.AddEntityIDs(ids...)
	return fuo
}

// AddEntities adds the "entities" edges to the Entity entity.
func (fuo *FileUpdateOne) AddEntities(e ...*Entity) *FileUpdateOne {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return fuo.AddEntityIDs(ids...)
}

// AddShareIDs adds the "shares" edge to the Share entity by IDs.
func (fuo *FileUpdateOne) AddShareIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.AddShareIDs(ids...)
	return fuo
}

// AddShares adds the "shares" edges to the Share entity.
func (fuo *FileUpdateOne) AddShares(s ...*Share) *FileUpdateOne {
	ids := make([]int, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return fuo.AddShareIDs(ids...)
}

// AddDirectLinkIDs adds the "direct_links" edge to the DirectLink entity by IDs.
func (fuo *FileUpdateOne) AddDirectLinkIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.AddDirectLinkIDs(ids...)
	return fuo
}

// AddDirectLinks adds the "direct_links" edges to the DirectLink entity.
func (fuo *FileUpdateOne) AddDirectLinks(d ...*DirectLink) *FileUpdateOne {
	ids := make([]int, len(d))
	for i := range d {
		ids[i] = d[i].ID
	}
	return fuo.AddDirectLinkIDs(ids...)
}

// Mutation returns the FileMutation object of the builder.
func (fuo *FileUpdateOne) Mutation() *FileMutation {
	return fuo.mutation
}

// ClearOwner clears the "owner" edge to the User entity.
func (fuo *FileUpdateOne) ClearOwner() *FileUpdateOne {
	fuo.mutation.ClearOwner()
	return fuo
}

// ClearStoragePolicies clears the "storage_policies" edge to the StoragePolicy entity.
func (fuo *FileUpdateOne) ClearStoragePolicies() *FileUpdateOne {
	fuo.mutation.ClearStoragePolicies()
	return fuo
}

// ClearParent clears the "parent" edge to the File entity.
func (fuo *FileUpdateOne) ClearParent() *FileUpdateOne {
	fuo.mutation.ClearParent()
	return fuo
}

// ClearChildren clears all "children" edges to the File entity.
func (fuo *FileUpdateOne) ClearChildren() *FileUpdateOne {
	fuo.mutation.ClearChildren()
	return fuo
}

// RemoveChildIDs removes the "children" edge to File entities by IDs.
func (fuo *FileUpdateOne) RemoveChildIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.RemoveChildIDs(ids...)
	return fuo
}

// RemoveChildren removes "children" edges to File entities.
func (fuo *FileUpdateOne) RemoveChildren(f ...*File) *FileUpdateOne {
	ids := make([]int, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return fuo.RemoveChildIDs(ids...)
}

// ClearMetadata clears all "metadata" edges to the Metadata entity.
func (fuo *FileUpdateOne) ClearMetadata() *FileUpdateOne {
	fuo.mutation.ClearMetadata()
	return fuo
}

// RemoveMetadatumIDs removes the "metadata" edge to Metadata entities by IDs.
func (fuo *FileUpdateOne) RemoveMetadatumIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.RemoveMetadatumIDs(ids...)
	return fuo
}

// RemoveMetadata removes "metadata" edges to Metadata entities.
func (fuo *FileUpdateOne) RemoveMetadata(m ...*Metadata) *FileUpdateOne {
	ids := make([]int, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return fuo.RemoveMetadatumIDs(ids...)
}

// ClearEntities clears all "entities" edges to the Entity entity.
func (fuo *FileUpdateOne) ClearEntities() *FileUpdateOne {
	fuo.mutation.ClearEntities()
	return fuo
}

// RemoveEntityIDs removes the "entities" edge to Entity entities by IDs.
func (fuo *FileUpdateOne) RemoveEntityIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.RemoveEntityIDs(ids...)
	return fuo
}

// RemoveEntities removes "entities" edges to Entity entities.
func (fuo *FileUpdateOne) RemoveEntities(e ...*Entity) *FileUpdateOne {
	ids := make([]int, len(e))
	for i := range e {
		ids[i] = e[i].ID
	}
	return fuo.RemoveEntityIDs(ids...)
}

// ClearShares clears all "shares" edges to the Share entity.
func (fuo *FileUpdateOne) ClearShares() *FileUpdateOne {
	fuo.mutation.ClearShares()
	return fuo
}

// RemoveShareIDs removes the "shares" edge to Share entities by IDs.
func (fuo *FileUpdateOne) RemoveShareIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.RemoveShareIDs(ids...)
	return fuo
}

// RemoveShares removes "shares" edges to Share entities.
func (fuo *FileUpdateOne) RemoveShares(s ...*Share) *FileUpdateOne {
	ids := make([]int, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return fuo.RemoveShareIDs(ids...)
}

// ClearDirectLinks clears all "direct_links" edges to the DirectLink entity.
func (fuo *FileUpdateOne) ClearDirectLinks() *FileUpdateOne {
	fuo.mutation.ClearDirectLinks()
	return fuo
}

// RemoveDirectLinkIDs removes the "direct_links" edge to DirectLink entities by IDs.
func (fuo *FileUpdateOne) RemoveDirectLinkIDs(ids ...int) *FileUpdateOne {
	fuo.mutation.RemoveDirectLinkIDs(ids...)
	return fuo
}

// RemoveDirectLinks removes "direct_links" edges to DirectLink entities.
func (fuo *FileUpdateOne) RemoveDirectLinks(d ...*DirectLink) *FileUpdateOne {
	ids := make([]int, len(d))
	for i := range d {
		ids[i] = d[i].ID
	}
	return fuo.RemoveDirectLinkIDs(ids...)
}

// Where appends a list predicates to the FileUpdate builder.
func (fuo *FileUpdateOne) Where(ps ...predicate.File) *FileUpdateOne {
	fuo.mutation.Where(ps...)
	return fuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne {
	fuo.fields = append([]string{field}, fields...)
	return fuo
}

// Save executes the query and returns the updated File entity.
func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) {
	return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (fuo *FileUpdateOne) SaveX(ctx context.Context) *File {
	node, err := fuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (fuo *FileUpdateOne) Exec(ctx context.Context) error {
	_, err := fuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (fuo *FileUpdateOne) ExecX(ctx context.Context) {
	if err := fuo.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (fuo *FileUpdateOne) check() error {
	if _, ok := fuo.mutation.OwnerID(); fuo.mutation.OwnerCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "File.owner"`)
	}
	return nil
}

func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) {
	if err := fuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt))
	id, ok := fuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "File.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := fuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, file.FieldID)
		for _, f := range fields {
			if !file.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != file.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := fuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := fuo.mutation.UpdatedAt(); ok {
		_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := fuo.mutation.GetType(); ok {
		_spec.SetField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := fuo.mutation.AddedType(); ok {
		_spec.AddField(file.FieldType, field.TypeInt, value)
	}
	if value, ok := fuo.mutation.Name(); ok {
		_spec.SetField(file.FieldName, field.TypeString, value)
	}
	if value, ok := fuo.mutation.Size(); ok {
		_spec.SetField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := fuo.mutation.AddedSize(); ok {
		_spec.AddField(file.FieldSize, field.TypeInt64, value)
	}
	if value, ok := fuo.mutation.PrimaryEntity(); ok {
		_spec.SetField(file.FieldPrimaryEntity, field.TypeInt, value)
	}
	if value, ok := fuo.mutation.AddedPrimaryEntity(); ok {
		_spec.AddField(file.FieldPrimaryEntity, field.TypeInt, value)
	}
	if fuo.mutation.PrimaryEntityCleared() {
		_spec.ClearField(file.FieldPrimaryEntity, field.TypeInt)
	}
	if value, ok := fuo.mutation.IsSymbolic(); ok {
		_spec.SetField(file.FieldIsSymbolic, field.TypeBool, value)
	}
	if value, ok := fuo.mutation.Props(); ok {
		_spec.SetField(file.FieldProps, field.TypeJSON, value)
	}
	if fuo.mutation.PropsCleared() {
		_spec.ClearField(file.FieldProps, field.TypeJSON)
	}
	if fuo.mutation.OwnerCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.OwnerIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.OwnerTable,
			Columns: []string{file.OwnerColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.StoragePoliciesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.StoragePoliciesTable,
			Columns: []string{file.StoragePoliciesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.StoragePoliciesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.StoragePoliciesTable,
			Columns: []string{file.StoragePoliciesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.ParentCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.ParentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   file.ParentTable,
			Columns: []string{file.ParentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !fuo.mutation.ChildrenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.ChildrenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.ChildrenTable,
			Columns: []string{file.ChildrenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RemovedMetadataIDs(); len(nodes) > 0 && !fuo.mutation.MetadataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.MetadataIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.MetadataTable,
			Columns: []string{file.MetadataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   file.EntitiesTable,
			Columns: file.EntitiesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RemovedEntitiesIDs(); len(nodes) > 0 && !fuo.mutation.EntitiesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   file.EntitiesTable,
			Columns: file.EntitiesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.EntitiesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   file.EntitiesTable,
			Columns: file.EntitiesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.SharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.SharesTable,
			Columns: []string{file.SharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RemovedSharesIDs(); len(nodes) > 0 && !fuo.mutation.SharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.SharesTable,
			Columns: []string{file.SharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.SharesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.SharesTable,
			Columns: []string{file.SharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.DirectLinksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.DirectLinksTable,
			Columns: []string{file.DirectLinksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RemovedDirectLinksIDs(); len(nodes) > 0 && !fuo.mutation.DirectLinksCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.DirectLinksTable,
			Columns: []string{file.DirectLinksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.DirectLinksIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   file.DirectLinksTable,
			Columns: []string{file.DirectLinksColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(directlink.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &File{config: fuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, fuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{file.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	fuo.mutation.done = true
	return _node, nil
}
