(ctx context.Context, path string)
| 171 | } |
| 172 | |
| 173 | func (d *Crypt) Get(ctx context.Context, path string) (model.Obj, error) { |
| 174 | firstTryIsFolder, secondTry := guessPath(path) |
| 175 | remoteFullPath := stdpath.Join(d.RemotePath, d.encryptPath(path, firstTryIsFolder)) |
| 176 | remoteObj, err := fs.Get(ctx, remoteFullPath, &fs.GetArgs{NoLog: true}) |
| 177 | if err != nil { |
| 178 | if errors.Is(err, errs.StorageNotFound) { |
| 179 | remoteFullPath = stdpath.Join(d.RemotePath, path) |
| 180 | remoteObj, err = fs.Get(ctx, remoteFullPath, &fs.GetArgs{NoLog: true}) |
| 181 | if err != nil { |
| 182 | // 可能是 虚拟路径+开启文件夹加密:返回NotSupport让op.Get去尝试op.List查找 |
| 183 | return nil, errs.NotSupport |
| 184 | } |
| 185 | } else if secondTry && errs.IsObjectNotFound(err) { |
| 186 | // try the opposite |
| 187 | remoteFullPath = stdpath.Join(d.RemotePath, d.encryptPath(path, !firstTryIsFolder)) |
| 188 | remoteObj, err = fs.Get(ctx, remoteFullPath, &fs.GetArgs{NoLog: true}) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | } else { |
| 193 | return nil, err |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | size := remoteObj.GetSize() |
| 198 | name := remoteObj.GetName() |
| 199 | mask := model.GetObjMask(remoteObj) &^ model.Temp |
| 200 | if mask&model.Virtual == 0 { |
| 201 | if !remoteObj.IsDir() { |
| 202 | decryptedSize, err := d.cipher.DecryptedSize(size) |
| 203 | if err != nil { |
| 204 | log.Warnf("DecryptedSize failed for %s ,will use original size, err:%s", path, err) |
| 205 | } else { |
| 206 | size = decryptedSize |
| 207 | } |
| 208 | decryptedName, err := d.cipher.DecryptFileName(model.UnwrapObjName(remoteObj).GetName()) |
| 209 | if err != nil { |
| 210 | log.Warnf("DecryptFileName failed for %s ,will use original name, err:%s", path, err) |
| 211 | } else { |
| 212 | name = decryptedName |
| 213 | } |
| 214 | } else { |
| 215 | decryptedName, err := d.cipher.DecryptDirName(model.UnwrapObjName(remoteObj).GetName()) |
| 216 | if err != nil { |
| 217 | log.Warnf("DecryptDirName failed for %s ,will use original name, err:%s", path, err) |
| 218 | } else { |
| 219 | name = decryptedName |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | return &model.Object{ |
| 224 | Path: remoteFullPath, |
| 225 | Name: name, |
| 226 | Size: size, |
| 227 | Modified: remoteObj.ModTime(), |
| 228 | IsFolder: remoteObj.IsDir(), |
| 229 | Ctime: remoteObj.CreateTime(), |
| 230 | Mask: mask, |
nothing calls this directly
no test coverage detected