~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/os/file_plan9.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
313
313
        return nil
314
314
}
315
315
 
316
 
// Rename renames a file.
317
 
func Rename(oldname, newname string) error {
 
316
// HasPrefix from the strings package.
 
317
func hasPrefix(s, prefix string) bool {
 
318
        return len(s) >= len(prefix) && s[0:len(prefix)] == prefix
 
319
}
 
320
 
 
321
// Variant of LastIndex from the strings package.
 
322
func lastIndex(s string, sep byte) int {
 
323
        for i := len(s) - 1; i >= 0; i-- {
 
324
                if s[i] == sep {
 
325
                        return i
 
326
                }
 
327
        }
 
328
        return -1
 
329
}
 
330
 
 
331
func rename(oldname, newname string) error {
 
332
        dirname := oldname[:lastIndex(oldname, '/')+1]
 
333
        if hasPrefix(newname, dirname) {
 
334
                newname = newname[len(dirname):]
 
335
        } else {
 
336
                return &LinkError{"rename", oldname, newname, ErrInvalid}
 
337
        }
 
338
 
 
339
        // If newname still contains slashes after removing the oldname
 
340
        // prefix, the rename is cross-directory and must be rejected.
 
341
        // This case is caught by d.Marshal below.
 
342
 
318
343
        var d syscall.Dir
319
344
 
320
345
        d.Null()
323
348
        buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
324
349
        n, err := d.Marshal(buf[:])
325
350
        if err != nil {
326
 
                return &PathError{"rename", oldname, err}
 
351
                return &LinkError{"rename", oldname, newname, err}
327
352
        }
328
353
        if err = syscall.Wstat(oldname, buf[:n]); err != nil {
329
 
                return &PathError{"rename", oldname, err}
 
354
                return &LinkError{"rename", oldname, newname, err}
330
355
        }
331
356
        return nil
332
357
}