@@ -20,15 +20,16 @@ import (
2020//
2121// Will definitely have info but maybe not meta
2222type Object struct {
23- fs * Fs // what this object is part of
24- remote string // The remote path base root relativePath path,have file name
25- size int64 // size of the object
26- modTime time.Time // modification time of the object
27- id string // ID of the object
28- parentId string
29- fileName string
30- isLink bool
31- linkToPath string
23+ fs * Fs // what this object is part of
24+ remote string // The remote path base root relativePath path,have file name
25+ size int64 // size of the object
26+ modTime time.Time // modification time of the object
27+ id string // ID of the object
28+ parentId string
29+ fileName string
30+ isLink bool
31+ linkToPath string // 如果linkToPath为""则软链接为相对路径,使用LinkToLocalPath
32+ LinkToLocalPath string
3233}
3334
3435// ------------------------------------------------------------
@@ -45,15 +46,16 @@ func NewObjectFromFileInfo(file *FileInfo, absolutePath string, f *Fs) *Object {
4546 }
4647 } else {
4748 return & Object {
48- id : file .Id ,
49- parentId : file .ParentId ,
50- remote : absolutePath ,
51- modTime : file .ModTime ,
52- size : file .FileSize ,
53- fs : f ,
54- fileName : file .Name ,
55- isLink : file .IsLink ,
56- linkToPath : file .LinkToPath ,
49+ id : file .Id ,
50+ parentId : file .ParentId ,
51+ remote : absolutePath ,
52+ modTime : file .ModTime ,
53+ size : file .FileSize ,
54+ fs : f ,
55+ fileName : file .Name ,
56+ isLink : file .IsLink ,
57+ linkToPath : file .LinkToPath ,
58+ LinkToLocalPath : file .LinkToLocalPath ,
5759 }
5860 }
5961}
@@ -97,6 +99,10 @@ func (o *Object) ModTime(ctx context.Context) time.Time {
9799// SetModTime sets the modification time of the local fs object
98100func (o * Object ) SetModTime (ctx context.Context , modTime time.Time ) error {
99101 o .modTime = modTime
102+ result := o .fs .db .Where ("id = ?" , o .id ).Updates (FileInfo {ModTime : modTime })
103+ if result .Error != nil {
104+ return errors .Wrap (result .Error , "SetModTime error" )
105+ }
100106 return nil
101107}
102108
@@ -110,7 +116,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
110116
111117 //如果打开的软链接文件,需要特殊处理
112118 if ! o .fs .opt .IsLinkFileMode && o .isLink {
113- linkToFileInfo , err := o .fs .findRealLinkedToFileInfo (ctx , o . linkToPath , false )
119+ linkToFileInfo , err := o .fs .findRealLinkedToFileInfo (ctx , FileInfo { IsDir : false , LinkToLocalPath : o . LinkToLocalPath , LinkToPath : o . linkToPath , IsLink : o . isLink } , false )
114120 if err != nil {
115121 return nil , err
116122 }
@@ -226,22 +232,28 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
226232 //}
227233
228234 linkToPath := string (allByte )
229- linkToFileInfo , err := os .Stat (linkToPath )
230- if err != nil {
231- return err
232- }
233- fileInfo .LinkToLocalPath = linkToPath
234- srcLinkPath := strings .TrimSuffix (path .Join (src .Fs ().Root (), src .Remote ()), linkSuffix )
235- dstLinkPath := strings .TrimSuffix (path .Join (o .fs .root , o .remote ), linkSuffix )
235+ if paths .IsAbs (linkToPath ) {
236+ linkToFileInfo , err := os .Stat (linkToPath )
237+ if err != nil {
238+ return err
239+ }
240+ fileInfo .LinkToLocalPath = linkToPath
241+ srcLinkPath := strings .TrimSuffix (path .Join (src .Fs ().Root (), src .Remote ()), linkSuffix )
242+ dstLinkPath := strings .TrimSuffix (path .Join (o .fs .root , o .remote ), linkSuffix )
236243
237- fileInfo .IsDir = linkToFileInfo .IsDir ()
238- derivedPathFromRelative , err := ResolveDerivedPathFromRelative (srcLinkPath , linkToPath , dstLinkPath , fileInfo .IsDir )
239- if err != nil {
240- //如果转化的路径超过了绝对路径的根路径就会报错
241- return err
244+ fileInfo .IsDir = linkToFileInfo .IsDir ()
245+ derivedPathFromRelative , err := ResolveDerivedPathFromRelative (srcLinkPath , linkToPath , dstLinkPath , fileInfo .IsDir )
246+ if err != nil {
247+ //如果转化的路径超过了绝对路径的根路径就会报错
248+ return err
249+ } else {
250+ fileInfo .LinkToPath = derivedPathFromRelative
251+ }
242252 } else {
243- fileInfo .LinkToPath = derivedPathFromRelative
253+ fileInfo .LinkToLocalPath = ""
254+ fileInfo .LinkToPath = linkToPath
244255 }
256+
245257 //// 文件夹链接大小定为-1,文件链接大小定为0
246258 //if linkToFileInfo.IsDir() {
247259 // fileInfo.FileSize = -1
@@ -251,7 +263,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
251263 }
252264 tx := o .fs .db
253265 var oldFileInfos []FileInfo
254- db := tx .Find (& oldFileInfos , & FileInfo {ParentId : o .parentId , Name : o . fileName })
266+ db := tx .Find (& oldFileInfos , & FileInfo {ParentId : o .parentId , Name : fileInfo . Name })
255267 if db .Error != nil {
256268 //tx.Rollback()
257269 return errors .Wrapf (db .Error , "Error update object %s" , o )
@@ -274,7 +286,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
274286 //只有原本文件存在时,才会进行更新,如果文件不存在,则应该是走创建链接文件的逻辑,而不是这里
275287 //如果打开的软链接文件,需要特殊处理
276288 if ! o .fs .opt .IsLinkFileMode && oldFileInfo .IsLink {
277- linkToFileInfo , err := o .fs .findRealLinkedToFileInfo (ctx , oldFileInfo . LinkToPath , false )
289+ linkToFileInfo , err := o .fs .findRealLinkedToFileInfo (ctx , oldFileInfo , false )
278290 if err != nil {
279291 return err
280292 }
0 commit comments