vaults

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 16 Imported by: 0

README

The vaults page

The vaults is a major part of FreePDM. It is primarily a storage of files that are stored into the server. The primary goals are to import / export files, the revision of files, moving -, copying and renaming of files, and all with access control. To make this happen you want to check-out and check-in of files, so that others know that you checked out a file and can't modify / edit the file without notifying you. The filesystem use directories, just like ordinary directories, to organize the files. The storage of files allows that you can also open a previous file.

Todo:

  • Add a filesystem (directories)
  • Allow importing of files
  • Allow showing and editing files with SMB
  • Renaming files
  • Copying files
  • Moving files
  • Renaming directories
  • Copying directories
  • Dealing with versions.
  • Disable / enable versioned files (mode 0700)
  • Dealing with checkin and checkout.
  • Dealing with users.
  • Reporting with json (dir list, properties, etc.)
  • Logging the activities.
  • Checks about checkout during file operations (rename, copy) and new versions.
  • Make it working for multi-user, multi-vaults
  • Checks about CheckIn comments (descr and longDescr)
  • Checks about the VER.txt in file versions
  • Change directory and file structure to Read Only for security. That way no accidental issues can happen.
  • Move the vaultsdata dir to the root of the vault dir under .data and the files are read only.
  • Set the owner of the vault root dir to root:sambashare. This means that some apps needs sudo.

Documentation

Index

Constants

View Source
const (
	Properties      = "Properties.txt"
	Description     = "Description.txt"
	LongDescription = "LongDescription.txt"
	Ver             = "VER.txt"
)

Some handy file names

View Source
const (
	LockedFileCsv = "LockedFiles.csv"
)

Variables

This section is empty.

Functions

func ListVaults

func ListVaults() ([]string, error)

ListVaults returns the vault names

func Root

func Root() string

Root returns the root of the vaults directory

func RootData

func RootData() string

RootData returns the root of the vaultsdata directory

func SplitExt

func SplitExt(path string) (base, ext string)

Splits a file with its base and extension

Types

type FileDirectory

type FileDirectory struct {
	// contains filtered or unexported fields
}

File Directory related struct.

func NewFileDirectory

func NewFileDirectory(fsm *FileSystem, fl FileList) FileDirectory

Initializes the FileDirectory struct. Parameters: fsm is necessary because of this struct containerNumber means the directory in where to put the file structure fileNumber means the file number, which is an int64

func (*FileDirectory) AllFileVersions

func (fd *FileDirectory) AllFileVersions() ([]FileVersion, error)

Returns all file versions name from file or an error.

func (*FileDirectory) CloseItemVersion

func (fd *FileDirectory) CloseItemVersion(version FileVersion)

Closes item number for editing.

func (*FileDirectory) CloseLatestsVersion

func (fd *FileDirectory) CloseLatestsVersion()

Closes the latest version for editing.

func (*FileDirectory) CreateDirectory

func (fd *FileDirectory) CreateDirectory() error

Creates a new directory inside the current working directory.

func (*FileDirectory) DeleteVersion

func (fd *FileDirectory) DeleteVersion(item int)

Delete one version, not the file on its own. The stored file should be put in the archive, but not deleted AND also not visible.

func (FileDirectory) FileList

func (fd FileDirectory) FileList() FileList

Returns the FileList because this field is unexported

func (FileDirectory) ImportNewFile

func (fd FileDirectory) ImportNewFile(fname string) error

Imports a file from an external source.

func (FileDirectory) LatestProperties

func (fd FileDirectory) LatestProperties() []FileProperties

Returns the file properties of the latest version

func (*FileDirectory) LatestVersion

func (fd *FileDirectory) LatestVersion() FileVersion

Returns the latest version.

func (FileDirectory) NewVersion

func (fd FileDirectory) NewVersion() FileVersion

Creates a new version from copying the previous version.

func (*FileDirectory) OpenItemVersion

func (fd *FileDirectory) OpenItemVersion(version FileVersion)

Opens the item number for editing. This "Checks Out" the item.

func (*FileDirectory) OpenLatestsVersion

func (fd *FileDirectory) OpenLatestsVersion()

Opens the latest item for editing the SMB mount. This "Checks Out" the item.

func (FileDirectory) Properties

func (fd FileDirectory) Properties(version FileVersion) []FileProperties

Returns the file properties of the specific version

func (*FileDirectory) Restoreversion

func (fd *FileDirectory) Restoreversion(item int)

Restore one version. Also restore the item from the filesystem indexes.

func (FileDirectory) SetLatestProperties

func (fd FileDirectory) SetLatestProperties(props []FileProperties)

Sets the file properties of the latest version

func (FileDirectory) SetProperties

func (fd FileDirectory) SetProperties(version FileVersion, props []FileProperties)

Sets the file properties of the specific version

func (FileDirectory) StoreData

func (fd FileDirectory) StoreData(version FileVersion, descr, longDescr string)

Stores the description and long description text.

type FileIndex

type FileIndex struct {
	// contains filtered or unexported fields
}

File Index Files in the root

func NewFileIndex

func NewFileIndex(fs *FileSystem) (fi FileIndex, err error)

func (*FileIndex) AddItem

func (fi *FileIndex) AddItem(dirName, fileName string) (*FileList, error)

Adds the filename to the filelist. Returns the index number, and an error. It does not add a file on disk.

func (*FileIndex) ContainerNumberDir

func (fi *FileIndex) ContainerNumberDir(containerNumber string) (string, error)

Returns the complete directory name of a container number, or an error when not found.

func (*FileIndex) ContainerNumberToFileList

func (fi *FileIndex) ContainerNumberToFileList(containerNumber string) (FileList, error)

Returns the FileList struct from an container number, or an error when not found.

func (*FileIndex) ContainerNumberToFileName

func (fi *FileIndex) ContainerNumberToFileName(containerNumber string) (string, error)

Returns the file name of a container number.

func (*FileIndex) FileNameToContainerNumber

func (fi *FileIndex) FileNameToContainerNumber(dir, fileName string) (string, error)

Returns the index number of the file name in directory, or an error when the file is not found.

func (*FileIndex) FileNameToFileList

func (fi *FileIndex) FileNameToFileList(dir, fileName string) (FileList, error)

Input parameter is the file name. Returns the FileList and an error when not found.

func (*FileIndex) MoveItem

func (fi *FileIndex) MoveItem(src FileList, directory string) error

Moves the filename to an other directory, but only in the FileList, not on disk.

func (*FileIndex) Read

func (fi *FileIndex) Read() error

Reads the values from "FileList.txt"

func (*FileIndex) Write

func (fi *FileIndex) Write() error

Writes the values to "FileList.csv"

type FileInfo

type FileInfo struct {
	// contains filtered or unexported fields
}

The FileInfo struct

func (FileInfo) Description

func (fi FileInfo) Description() string

func (FileInfo) DirSort

func (fi FileInfo) DirSort() int

func (FileInfo) IsDir

func (fi FileInfo) IsDir() bool

func (FileInfo) IsLocked

func (fi FileInfo) IsLocked() bool

func (FileInfo) LockedOutBy

func (fi FileInfo) LockedOutBy() string

func (FileInfo) Name

func (fi FileInfo) Name() string

Returns the directory or file name

func (FileInfo) Path

func (fi FileInfo) Path() string

Returns the path of the file or dir

func (FileInfo) Properties

func (fi FileInfo) Properties() []FileProperties

func (FileInfo) SecondDescription

func (fi FileInfo) SecondDescription() string

func (FileInfo) String

func (fi FileInfo) String() string

func (FileInfo) Version

func (fi FileInfo) Version() string

type FileList

type FileList struct {
	// contains filtered or unexported fields
}

The FileList is a struct with five fields: * The container number. * The file name. * The previous name of the file. * The dir name of the storage. This is an offset of "mainPdmDir". * The previous directory name.

func NewFileList

func NewFileList(containerName, file, previousFile, dir, previousDir string) FileList

func (FileList) ContainerNumber

func (fl FileList) ContainerNumber() string

func (FileList) Name

func (fl FileList) Name() string

func (FileList) Path

func (fl FileList) Path() string

func (FileList) PathAndContainerNumber

func (fl FileList) PathAndContainerNumber() string

func (FileList) PreviousName

func (fl FileList) PreviousName() string

func (FileList) PreviousPath

func (fl FileList) PreviousPath() string

type FileProperties

type FileProperties struct {
	Key, Value string
}

The File Properties

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

File System related Class

func NewFileSystem

func NewFileSystem(vaultDir, userName string) (fs *FileSystem, err error)

Constructor

func (FileSystem) AbsNormal

func (fs FileSystem) AbsNormal(absolutePath string) (string, error)

AbsNormal returns a "normalized" path, with the offset from the vault directory

func (*FileSystem) Chdir

func (fs *FileSystem) Chdir(dir string) error

Chdir creates a directory or an error

func (*FileSystem) CheckIn

func (fs *FileSystem) CheckIn(fl FileList, version FileVersion, descr, longdescr string) error

Checkin means unlocking a container number. The description and long description are meant for storage.

func (*FileSystem) CheckOut

func (fs *FileSystem) CheckOut(fl FileList, version FileVersion) error

Checkout means locking a conainer number so that only you can use it.

func (FileSystem) DirExists

func (fs FileSystem) DirExists(dir string) bool

func (*FileSystem) DirectoryCopy

func (fs *FileSystem) DirectoryCopy(src, dst string) error

Copy a directory.

func (FileSystem) DirectoryRename

func (fs FileSystem) DirectoryRename(src, dst string) error

Move a directory.

func (*FileSystem) FileCopy

func (fs *FileSystem) FileCopy(src, dst string) error

Copy the latest file from src to dst and returns an error.

func (*FileSystem) FileRename

func (fs *FileSystem) FileRename(src, dst string) error

Rename a file, for instance when the user wants to use a file with a specified numbering system

func (FileSystem) GetItem

func (fs FileSystem) GetItem(dir, file string) (FileList, error)

Returns the number of an item

func (FileSystem) Getwd

func (fs FileSystem) Getwd() string

Getwd returns the working directory

func (*FileSystem) ImportFile

func (fs *FileSystem) ImportFile(dstDir, fileName string) (*FileList, error)

import a file inside the PDM. When you import a file the attributes also gets imported, which means uploaded to the server. When you import a file or files you are placing the new file in the directory dstDir. The new file inside the PDM gets a revision number automatically. The function returns the number of the imported file or an error.

func (*FileSystem) ImportUrl

func (fs *FileSystem) ImportUrl(dstDir, url string) (*FileList, error)

import a url inside the PDM. For the rest it works the same as ImportFile()

func (FileSystem) IsLocked

func (fs FileSystem) IsLocked(containerNumber string, version FileVersion) string

Check whether the conatiner number is locked. Returns the name of the user who locked it or empty when not locked.

func (FileSystem) IsLockedItem

func (fs FileSystem) IsLockedItem(containerNumber string) string

Check whether the container number is locked. Returns the name of the user who locked it or empty when not locked.

func (FileSystem) ListDir

func (fs FileSystem) ListDir(dirName string) ([]FileInfo, error)

ListDir lists the sorted directories and files within the specified directory name, as long as the directory is inside the vault.

func (FileSystem) ListTree

func (fs FileSystem) ListTree(dirName string) ([]FileInfo, error)

ListTree lists the sorted directories and files within the specified directory name, including subdirectories, as long as the directory is inside the vault.

func (FileSystem) ListWD

func (fs FileSystem) ListWD() ([]FileInfo, error)

ListWD lists the sorted directories and files of the current working directory.

func (FileSystem) Mkdir

func (fs FileSystem) Mkdir(dir string) error

Creates a new directory inside the current directory, with the correct uid and gid.

func (*FileSystem) NewVersion

func (fs *FileSystem) NewVersion(fl FileList) (FileVersion, error)

Generates a new version of a file. Returns the FileVersion and an error.

func (*FileSystem) ReadLockedIndex

func (fs *FileSystem) ReadLockedIndex() error

Updates the locked index by reading from the lockedTxt file.

func (*FileSystem) VaultDir

func (fs *FileSystem) VaultDir() string

Returns the Vault directory

func (*FileSystem) VaultName

func (fs *FileSystem) VaultName() string

VaultName returns the name of the current vault

func (FileSystem) Verify

func (fs FileSystem) Verify(fl FileList) error

Verifies wether the operation succeeded well. It checks the location and also the entry inside the FileList.

func (*FileSystem) WriteLockedIndex

func (fs *FileSystem) WriteLockedIndex() error

type FileVersion

type FileVersion struct {
	Number int16
	Pretty string
	Date   string
}

File versions struct

field: 'number', an increment
field: 'pretty' means a version presentation, such as A.1, 2.5.0, 4.0, 3 or A.

TODO This functionality hasn't been implemented yet... For the time being it just reports the string presentation of 'number'

field: 'date' means the time of a new version with the format "YYYY-MM-DD H:M:S"

type LockedIndex

type LockedIndex struct {
	// contains filtered or unexported fields
}

LockedIndex is the list of locked files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL