mirror of
https://github.com/restic/restic.git
synced 2024-12-21 23:33:03 +00:00
Improve comments and remove old redundant comments
This commit is contained in:
parent
49f5db7534
commit
5a0f7bb4b2
4 changed files with 31 additions and 29 deletions
|
@ -340,8 +340,6 @@ func decryptFile(pathPointer *uint16) error {
|
|||
|
||||
// nodeFillGenericAttributes fills in the generic attributes for windows like File Attributes,
|
||||
// Created time and Security Descriptors.
|
||||
// It also checks if the volume supports extended attributes and stores the result in a map
|
||||
// so that it does not have to be checked again for subsequent calls for paths in the same volume.
|
||||
func nodeFillGenericAttributes(node *restic.Node, path string, stat *ExtendedFileInfo) (err error) {
|
||||
isAds := restic.IsAds(path)
|
||||
var attrs restic.WindowsAttributes
|
||||
|
|
|
@ -46,11 +46,10 @@ const (
|
|||
TypeFileAttributes GenericAttributeType = "windows.file_attributes"
|
||||
// TypeSecurityDescriptor is the GenericAttributeType used for storing security descriptors including owner, group, discretionary access control list (DACL), system access control list (SACL)) for windows files within the generic attributes map.
|
||||
TypeSecurityDescriptor GenericAttributeType = "windows.security_descriptor"
|
||||
// TypeHasADS is the GenericAttributeType used for to indicate that a file has Alternate Data Streams attached to it.
|
||||
// The value will have a | separate list of the ADS attached to the file. Those files will have a generic attribute TypeIsADS.
|
||||
// TypeHasADS is the GenericAttributeType used to indicate that a file has Alternate Data Streams attached to it.
|
||||
// The value will have a array of the ADS attached to the file. Those files will have a generic attribute TypeIsADS.
|
||||
TypeHasADS GenericAttributeType = "windows.has_ads"
|
||||
// TypeIsADS is the GenericAttributeType used for to indicate that a file represents an Alternate Data Streams and is attached to (child of) a file in the value.
|
||||
// The file in the value will be a file which has a generic attribute TypeHasADS.
|
||||
// TypeIsADS is the GenericAttributeType with a boolean value used to indicate that the file represents an Alternate Data Stream.
|
||||
TypeIsADS GenericAttributeType = "windows.is_ads"
|
||||
|
||||
// Generic Attributes for other OS types should be defined here.
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
"github.com/restic/restic/internal/debug"
|
||||
)
|
||||
|
||||
const AdsSeparator = "|"
|
||||
|
||||
// WindowsAttributes are the genericAttributes for Windows OS
|
||||
type WindowsAttributes struct {
|
||||
// CreationTime is used for storing creation time for windows files.
|
||||
|
@ -21,10 +19,10 @@ type WindowsAttributes struct {
|
|||
// SecurityDescriptor is used for storing security descriptors which includes
|
||||
// owner, group, discretionary access control list (DACL), system access control list (SACL)
|
||||
SecurityDescriptor *[]byte `generic:"security_descriptor"`
|
||||
// HasADS is used for storing if a file has an Alternate Data Stream attached to it.
|
||||
// HasADS is used to indicate that a file has Alternate Data Streams attached to it.
|
||||
// The value will have a array of the ADS attached to the file. Those files will have a generic attribute TypeIsADS.
|
||||
HasADS *[]string `generic:"has_ads"`
|
||||
// IsADS is used for storing if a file is an Alternate Data Stream and is attached to (child of) a file in the value.
|
||||
// The file in the value will be a file which has a generic attribute TypeHasADS.
|
||||
// IsADS is used to indicate that the file represents an Alternate Data Stream.
|
||||
IsADS *bool `generic:"is_ads"`
|
||||
}
|
||||
|
||||
|
|
|
@ -12,17 +12,27 @@ import (
|
|||
)
|
||||
|
||||
// createOrOpenFile opens the file and handles the readonly attribute and ads related logic during file creation.
|
||||
// Readonly files - if an existing file is detected as readonly we clear the flag because otherwise we cannot
|
||||
//
|
||||
// Readonly files -
|
||||
// If an existing file is detected as readonly we clear the flag because otherwise we cannot
|
||||
// make changes to the file. The readonly attribute would be set again in the second pass when the attributes
|
||||
// are set if the file version being restored has the readonly bit.
|
||||
// ADS files need special handling - Each stream is treated as a separate file in restic. This method is called
|
||||
// for the main file which has the streams and for each stream.
|
||||
// If the ads stream calls this method first and the main file doesn't already exist, then creating the file
|
||||
//
|
||||
// ADS files need special handling -
|
||||
// Each stream is treated as a separate file in restic. This function is called for the main file which has the
|
||||
// streams and for each stream.
|
||||
// If the ads stream calls this function first and the main file doesn't already exist, then creating the file
|
||||
// for the streams causes the main file to automatically get created with 0 size. Hence we need to be careful
|
||||
// while creating the main file. If we blindly create it with the os.O_CREATE option, it could overwrite the
|
||||
// stream. However creating the stream with os.O_CREATE option does not overwrite the mainfile if it already
|
||||
// exists. It will simply attach the new stream to the main file if the main file existed, otherwise it will
|
||||
// while creating the main file after that. If we blindly create the main file with the os.O_CREATE option,
|
||||
// it could overwrite the file already created when the stream was created. However creating the stream with
|
||||
// os.O_CREATE option does not overwrite the mainfile if it already exists.
|
||||
// It will simply attach the new stream to the main file if the main file existed, otherwise it will
|
||||
// create the 0 size main file.
|
||||
// So we need to sync on the main file path if the file either has ads or is an ads file and then while creating
|
||||
// the main file, we need to check if the file already exists and if it does, we should not overwrite it
|
||||
// but instead we should simply return the file that we already created.
|
||||
//
|
||||
// Reduction in number of streams when restoring an old mainfile version -
|
||||
// Another case to handle is if the mainfile already had more streams and the file version being restored has
|
||||
// less streams, then the extra streams need to be removed from the main file. The stream names are present
|
||||
// as the value in the generic attribute TypeHasAds.
|
||||
|
@ -91,7 +101,7 @@ func openFileImpl(path string, createSize int64, fileInfo *fileInfo) (mainPath s
|
|||
// If the error was because access is denied,
|
||||
// the calling method will try to check if the file is readonly and if so, it tries to
|
||||
// remove the readonly attribute and call this openFileImpl method again once.
|
||||
// If this method throws access denied again, then it stops trying and return the error.
|
||||
// If this method throws access denied again, then it stops trying and returns the error.
|
||||
return mainPath, nil, err
|
||||
}
|
||||
//At this point readonly flag is already handled and we need not consider it anymore.
|
||||
|
@ -121,8 +131,7 @@ func handleCreateFile(path string, fileIn *os.File, isAdsRelated, hasAds, isAds,
|
|||
func handleCreateFileNonAds(path string, fileIn *os.File, isAlreadyExists bool) (file *os.File, err error) {
|
||||
// This is the simple case.
|
||||
if isAlreadyExists {
|
||||
// If the non-ads file already exists, return the file
|
||||
// that we already created without create option.
|
||||
// If the non-ads file already exists, return the file that we already created without create option.
|
||||
return fileIn, nil
|
||||
} else {
|
||||
// If the non-ads file did not exist, try creating the file with create flag.
|
||||
|
@ -132,15 +141,13 @@ func handleCreateFileNonAds(path string, fileIn *os.File, isAlreadyExists bool)
|
|||
|
||||
// handleCreateFileAds handles all the various combination of states while creating the ads related file if needed.
|
||||
func handleCreateFileAds(path string, fileIn *os.File, hasAds, isAds, isAlreadyExists bool) (file *os.File, err error) {
|
||||
// This is the simple case. We do not need to change the encryption attribute.
|
||||
if isAlreadyExists {
|
||||
// If the ads related file already exists and no change to encryption, return the file
|
||||
// that we already created without create option.
|
||||
// If the ads related file already exists, return the file that we already created without create option.
|
||||
return fileIn, nil
|
||||
} else {
|
||||
// If the ads related file did not exist, first check if it is a hasAds or isAds
|
||||
// If the ads related file did not exist, first check if it is an ads file or a file which has ads files attached.
|
||||
if isAds {
|
||||
// If it is an ads file, then we can simple open it with create options without worrying about overwriting.
|
||||
// If it is an ads file, then we can simply open it with create options without worrying about overwriting.
|
||||
return fs.OpenFile(path, fs.O_CREATE|fs.O_WRONLY|fs.O_NOFOLLOW, 0600)
|
||||
}
|
||||
if hasAds {
|
||||
|
@ -151,18 +158,18 @@ func handleCreateFileAds(path string, fileIn *os.File, hasAds, isAds, isAlreadyE
|
|||
if os.IsNotExist(err) {
|
||||
// We confirmed that the main file still doesn't exist after syncing.
|
||||
// Hence creating the file with the create flag.
|
||||
// Directly open the main file with create option as it should not be encrypted.
|
||||
return fs.OpenFile(path, fs.O_CREATE|fs.O_WRONLY|fs.O_NOFOLLOW, 0600)
|
||||
} else {
|
||||
// Some other error occured so stop processing and return it.
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
// This means that the main file exists now and requires no change to encryption. Simply return it.
|
||||
// This means that the main file exists now and we should simply return it,
|
||||
// it does not have the create flag.
|
||||
return file, err
|
||||
}
|
||||
}
|
||||
return nil, errors.New("invalid case for ads same file encryption")
|
||||
return nil, errors.New("invalid case for ads")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue