| 1272 | } |
| 1273 | |
| 1274 | func (c *Client) Link(srcPath, dstPath string) error { |
| 1275 | fullSrcPath := c.absPath(srcPath) |
| 1276 | info, err := c.lookupPath(fullSrcPath) |
| 1277 | if err != nil { |
| 1278 | return err |
| 1279 | } |
| 1280 | |
| 1281 | srcIno := info.Inode |
| 1282 | if !proto.IsRegular(info.Mode) { |
| 1283 | log.LogErrorf("Link: not regular, src_path(%s) src_ino(%v) mode(%v)\n", fullSrcPath, srcIno, proto.OsMode(info.Mode)) |
| 1284 | return syscall.EPERM |
| 1285 | } |
| 1286 | |
| 1287 | fullDstPath := c.absPath(dstPath) |
| 1288 | parentDir := gopath.Dir(fullDstPath) |
| 1289 | filename := gopath.Base(fullDstPath) |
| 1290 | info, err = c.lookupPath(parentDir) |
| 1291 | if err != nil { |
| 1292 | return err |
| 1293 | } |
| 1294 | parentIno := info.Inode |
| 1295 | |
| 1296 | info, err = c.mw.Link(parentIno, filename, srcIno, fullDstPath) |
| 1297 | if err != nil { |
| 1298 | log.LogErrorf("Link: src_path(%s) src_ino(%v) dst_path(%s) parent(%v) err(%v)\n", fullSrcPath, srcIno, fullDstPath, parentIno, err) |
| 1299 | return err |
| 1300 | } |
| 1301 | |
| 1302 | c.ic.Put(info) |
| 1303 | log.LogDebugf("Link: src_path(%s) src_ino(%v) dst_path(%s) dst_ino(%v) parent(%v)\n", fullSrcPath, srcIno, fullDstPath, info.Inode, parentIno) |
| 1304 | |
| 1305 | return nil |
| 1306 | } |
| 1307 | |
| 1308 | func (f *File) Fd() uint { |
| 1309 | return f.fd |