~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/os_win32/os_rename.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * See the file LICENSE for redistribution information.
 
3
 *
 
4
 * Copyright (c) 1997-2001
 
5
 *      Sleepycat Software.  All rights reserved.
 
6
 */
 
7
 
 
8
#include "db_config.h"
 
9
 
 
10
#ifndef lint
 
11
static const char revid[] = "$Id: os_rename.c,v 1.3 2001/01/25 18:23:00 bostic Exp $";
 
12
#endif /* not lint */
 
13
 
 
14
#include "db_int.h"
 
15
#include "os_jump.h"
 
16
 
 
17
/*
 
18
 * __os_rename --
 
19
 *      Rename a file.
 
20
 */
 
21
int
 
22
__os_rename(dbenv, old, new)
 
23
        DB_ENV *dbenv;
 
24
        const char *old, *new;
 
25
{
 
26
        int ret;
 
27
 
 
28
        ret = 0;
 
29
        if (__db_jump.j_rename != NULL) {
 
30
                if (__db_jump.j_rename(old, new) == -1)
 
31
                        ret = __os_get_errno();
 
32
        }
 
33
        else {
 
34
                /* Normally we would use a single MoveFileEx call with
 
35
                 * MOVEFILE_REPLACE_EXISTING flag to simulate Unix rename().
 
36
                 * But if the target file exists, and the two files' 8.3
 
37
                 * names are identical, a Windows bug causes the target file
 
38
                 * to be deleted, but the original file will not be renamed,
 
39
                 * and an ENOENT error will be returned.  (See MSDN for a
 
40
                 * description of the bug).
 
41
                 *
 
42
                 * After the failed call, a MoveFile seems to perform
 
43
                 * the rename correctly (even another call to MoveFileEx
 
44
                 * does not)!  The expense of this extra call only occurs
 
45
                 * on systems with the bug: Windows/98, for one, but
 
46
                 * apparently not Windows/NT and Windows/2000.
 
47
                 */
 
48
                if (MoveFileEx(old, new, MOVEFILE_REPLACE_EXISTING) != TRUE)
 
49
                        ret = __os_win32_errno();
 
50
                if (ret == ENOENT && MoveFile(old, new) == TRUE)
 
51
                        ret = 0;
 
52
        }
 
53
        if (ret != 0)
 
54
                __db_err(dbenv, "Rename %s %s: %s", old, new, strerror(ret));
 
55
 
 
56
        return (ret);
 
57
}