本文整理汇总了Golang中github.com/Symantec/Dominator/lib/filesystem.RegularInode类的典型用法代码示例。如果您正苦于以下问题:Golang RegularInode类的具体用法?Golang RegularInode怎么用?Golang RegularInode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RegularInode类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeRegularInode
func makeRegularInode(fullPathname string, inode *filesystem.RegularInode,
multiplyUsedObjects map[hash.Hash]uint64) {
var err error
if inode.Size > 0 {
objectPathname := path.Join(objectsDir,
objectcache.HashToFilename(inode.Hash))
numCopies := multiplyUsedObjects[inode.Hash]
if numCopies > 1 {
numCopies--
objectPathname += strings.Repeat("~", int(numCopies))
if numCopies < 2 {
delete(multiplyUsedObjects, inode.Hash)
}
}
err = os.Rename(objectPathname, fullPathname)
} else {
_, err = os.Create(fullPathname)
}
if err != nil {
logger.Println(err)
return
}
if err := inode.WriteMetadata(fullPathname); err != nil {
logger.Println(err)
} else {
if inode.Size > 0 {
logger.Printf("Made inode: %s from: %x\n", fullPathname, inode.Hash)
} else {
logger.Printf("Made empty inode: %s\n", fullPathname)
}
}
}
示例2: setComputedFileMtime
func setComputedFileMtime(requiredInode *filesystem.RegularInode,
subEntry *filesystem.DirectoryEntry) {
if requiredInode.MtimeSeconds >= 0 {
return
}
if subEntry != nil {
subInode := subEntry.Inode()
if subInode, ok := subInode.(*filesystem.RegularInode); ok {
if requiredInode.Hash == subInode.Hash {
requiredInode.MtimeNanoSeconds = subInode.MtimeNanoSeconds
requiredInode.MtimeSeconds = subInode.MtimeSeconds
return
}
}
}
requiredInode.MtimeSeconds = time.Now().Unix()
}
示例3: makeRegularInode
func makeRegularInode(fullPathname string,
inode *filesystem.RegularInode, multiplyUsedObjects map[hash.Hash]uint64,
objectsDir string, logger *log.Logger) error {
var objectPathname string
if inode.Size > 0 {
objectPathname = path.Join(objectsDir,
objectcache.HashToFilename(inode.Hash))
numCopies := multiplyUsedObjects[inode.Hash]
if numCopies > 1 {
numCopies--
objectPathname += fmt.Sprintf("~%d~", numCopies)
if numCopies < 2 {
delete(multiplyUsedObjects, inode.Hash)
} else {
multiplyUsedObjects[inode.Hash] = numCopies
}
}
} else {
objectPathname = fmt.Sprintf("%s.empty.%d", fullPathname, os.Getpid())
if file, err := os.OpenFile(objectPathname,
os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600); err != nil {
return err
} else {
file.Close()
}
}
if err := fsutil.ForceRename(objectPathname, fullPathname); err != nil {
logger.Println(err)
return err
}
if err := inode.WriteMetadata(fullPathname); err != nil {
logger.Println(err)
return err
} else {
if inode.Size > 0 {
logger.Printf("Made inode: %s from: %x\n",
fullPathname, inode.Hash)
} else {
logger.Printf("Made empty inode: %s\n", fullPathname)
}
}
return nil
}
示例4: makeRegularInode
func makeRegularInode(stat *syscall.Stat_t) *filesystem.RegularInode {
var inode filesystem.RegularInode
inode.Mode = filesystem.FileMode(stat.Mode)
inode.Uid = stat.Uid
inode.Gid = stat.Gid
inode.MtimeSeconds = stat.Mtim.Sec
inode.MtimeNanoSeconds = int32(stat.Mtim.Nsec)
inode.Size = uint64(stat.Size)
return &inode
}
示例5: processFileUpdates
func (sub *Sub) processFileUpdates() bool {
haveUpdates := false
for {
image := sub.requiredImage
if image != nil && sub.computedInodes == nil {
sub.computedInodes = make(map[string]*filesystem.RegularInode)
sub.busyFlagMutex.Lock()
if sub.deleting {
sub.busyFlagMutex.Unlock()
return false
}
sub.herd.computedFilesManager.Update(
filegenclient.Machine{sub.mdb, sub.getComputedFiles(image)})
sub.busyFlagMutex.Unlock()
}
select {
case fileInfos := <-sub.fileUpdateChannel:
if image == nil {
continue
}
filenameToInodeTable := image.FileSystem.FilenameToInodeTable()
for _, fileInfo := range fileInfos {
inum, ok := filenameToInodeTable[fileInfo.Pathname]
if !ok {
continue
}
genericInode, ok := image.FileSystem.InodeTable[inum]
if !ok {
continue
}
cInode, ok := genericInode.(*filesystem.ComputedRegularInode)
if !ok {
continue
}
rInode := new(filesystem.RegularInode)
rInode.Mode = cInode.Mode
rInode.Uid = cInode.Uid
rInode.Gid = cInode.Gid
rInode.MtimeSeconds = -1 // The time is set during the compute.
rInode.Size = fileInfo.Length
rInode.Hash = fileInfo.Hash
sub.computedInodes[fileInfo.Pathname] = rInode
haveUpdates = true
}
default:
return haveUpdates
}
}
return haveUpdates
}
示例6: getRegularInode
func (fileSystem *FileSystem) getRegularInode(stat *syscall.Stat_t) (
*filesystem.RegularInode, bool) {
inode := fileSystem.RegularInodeTable[stat.Ino]
new := false
if inode == nil {
var _inode filesystem.RegularInode
inode = &_inode
_inode.Mode = filesystem.FileMode(stat.Mode)
_inode.Uid = stat.Uid
_inode.Gid = stat.Gid
_inode.MtimeSeconds = stat.Mtim.Sec
_inode.MtimeNanoSeconds = int32(stat.Mtim.Nsec)
_inode.Size = uint64(stat.Size)
fileSystem.RegularInodeTable[stat.Ino] = inode
new = true
}
return inode, new
}
示例7: addRegularFile
func (decoderData *decoderData) addRegularFile(tarReader *tar.Reader,
hasher Hasher, header *tar.Header, parent *filesystem.DirectoryInode,
name string) error {
var newInode filesystem.RegularInode
newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) |
syscall.S_IFREG)
newInode.Uid = uint32(header.Uid)
newInode.Gid = uint32(header.Gid)
newInode.MtimeNanoSeconds = int32(header.ModTime.Nanosecond())
newInode.MtimeSeconds = header.ModTime.Unix()
newInode.Size = uint64(header.Size)
if header.Size > 0 {
var err error
newInode.Hash, err = hasher.Hash(tarReader, uint64(header.Size))
if err != nil {
return err
}
}
decoderData.addEntry(parent, header.Name, name, &newInode)
return nil
}
示例8: addRegularFile
func (decoderData *decoderData) addRegularFile(tarReader *tar.Reader,
dataHandler DataHandler, header *tar.Header, parent *filesystem.Directory,
name string) error {
var newInode filesystem.RegularInode
newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) |
syscall.S_IFREG)
newInode.Uid = uint32(header.Uid)
newInode.Gid = uint32(header.Gid)
newInode.MtimeNanoSeconds = int32(header.ModTime.Nanosecond())
newInode.MtimeSeconds = header.ModTime.Unix()
newInode.Size = uint64(header.Size)
if header.Size > 0 {
data, err := ioutil.ReadAll(tarReader)
if err != nil {
return errors.New("error reading file data" + err.Error())
}
if int64(len(data)) != header.Size {
return errors.New(fmt.Sprintf(
"failed to read file data, wanted: %d, got: %d bytes",
header.Size, len(data)))
}
newInode.Hash, err = dataHandler.HandleData(data)
if err != nil {
return err
}
}
decoderData.regularInodeTable[header.Name] = decoderData.nextInodeNumber
decoderData.fileSystem.RegularInodeTable[decoderData.nextInodeNumber] =
&newInode
var newEntry filesystem.RegularFile
newEntry.Name = name
newEntry.InodeNumber = decoderData.nextInodeNumber
parent.RegularFileList = append(parent.RegularFileList, &newEntry)
decoderData.nextInodeNumber++
return nil
}