* Fixed BDirectory::SetTo(BDirectory*, path) constructor in case the target

directory was "this".
* Fixed storage_support.h header - didn't include all needed headers.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17288 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-05-01 16:55:46 +00:00
parent 9991d2b1ac
commit 3e54c13abc
2 changed files with 55 additions and 50 deletions
+13 -6
View File
@@ -1,19 +1,26 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
*/
#ifndef _STORAGE_SUPPORT_H
#define _STORAGE_SUPPORT_H
/*! /*!
\file storage_support.h \file storage_support.h
Interface declarations for miscellaneous internal Interface declarations for miscellaneous internal
Storage Kit support functions. Storage Kit support functions.
*/ */
#ifndef _STORAGE_SUPPORT_H #include <StorageDefs.h>
#define _STORAGE_SUPPORT_H #include <SupportDefs.h>
#include <dirent.h> #include <dirent.h>
#include <string> #include <string>
namespace BPrivate { namespace BPrivate {
namespace Storage { namespace Storage {
+35 -37
View File
@@ -1,14 +1,17 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
/*! * Authors:
\file Directory.cpp * Tyler Dauwalder
BDirectory implementation. * Ingo Weinhold, [email protected]
*/ * Axel Dörfler, [email protected]
*/
#include <fcntl.h>
#include <string.h> #include "storage_support.h"
#include <syscalls.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
@@ -17,19 +20,14 @@
#include <Path.h> #include <Path.h>
#include <SymLink.h> #include <SymLink.h>
#include <syscalls.h> #include <fcntl.h>
#include <string.h>
#include "storage_support.h"
#ifdef USE_OPENBEOS_NAMESPACE
namespace OpenBeOS {
#endif
// constructor // constructor
//! Creates an uninitialized BDirectory object. //! Creates an uninitialized BDirectory object.
BDirectory::BDirectory() BDirectory::BDirectory()
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
} }
@@ -39,8 +37,7 @@ BDirectory::BDirectory()
/*! \param dir the BDirectory object to be copied /*! \param dir the BDirectory object to be copied
*/ */
BDirectory::BDirectory(const BDirectory &dir) BDirectory::BDirectory(const BDirectory &dir)
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
*this = dir; *this = dir;
@@ -52,8 +49,7 @@ BDirectory::BDirectory(const BDirectory &dir)
\param ref the entry_ref referring to the directory \param ref the entry_ref referring to the directory
*/ */
BDirectory::BDirectory(const entry_ref *ref) BDirectory::BDirectory(const entry_ref *ref)
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
SetTo(ref); SetTo(ref);
@@ -65,8 +61,7 @@ BDirectory::BDirectory(const entry_ref *ref)
\param nref the node_ref referring to the directory \param nref the node_ref referring to the directory
*/ */
BDirectory::BDirectory(const node_ref *nref) BDirectory::BDirectory(const node_ref *nref)
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
SetTo(nref); SetTo(nref);
@@ -78,8 +73,7 @@ BDirectory::BDirectory(const node_ref *nref)
\param entry the BEntry referring to the directory \param entry the BEntry referring to the directory
*/ */
BDirectory::BDirectory(const BEntry *entry) BDirectory::BDirectory(const BEntry *entry)
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
SetTo(entry); SetTo(entry);
@@ -91,8 +85,7 @@ BDirectory::BDirectory(const BEntry *entry)
\param path the directory's path name \param path the directory's path name
*/ */
BDirectory::BDirectory(const char *path) BDirectory::BDirectory(const char *path)
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
SetTo(path); SetTo(path);
@@ -106,8 +99,7 @@ BDirectory::BDirectory(const char *path)
\param path the directory's path name relative to \a dir \param path the directory's path name relative to \a dir
*/ */
BDirectory::BDirectory(const BDirectory *dir, const char *path) BDirectory::BDirectory(const BDirectory *dir, const char *path)
: BNode(), :
BEntryList(),
fDirFd(-1) fDirFd(-1)
{ {
SetTo(dir, path); SetTo(dir, path);
@@ -301,19 +293,30 @@ BDirectory::SetTo(const BDirectory *dir, const char *path)
return (fCStatus = B_BAD_VALUE); return (fCStatus = B_BAD_VALUE);
} }
int dirFD = dir->fDirFd;
if (dir == this) {
// prevent that our file descriptor goes away in _SetTo()
fDirFd = -1;
}
// open node // open node
status_t error = _SetTo(dir->fDirFd, path, true); status_t error = _SetTo(dirFD, path, true);
if (error != B_OK) if (error != B_OK)
return error; return error;
// open dir // open dir
fDirFd = _kern_open_dir(dir->fDirFd, path); fDirFd = _kern_open_dir(dirFD, path);
if (fDirFd < 0) { if (fDirFd < 0) {
status_t error = fDirFd; status_t error = fDirFd;
Unset(); Unset();
return (fCStatus = error); return (fCStatus = error);
} }
if (dir == this) {
// cleanup after _SetTo()
close(dirFD);
}
// set close on exec flag on dir FD // set close on exec flag on dir FD
fcntl(fDirFd, F_SETFD, FD_CLOEXEC); fcntl(fDirFd, F_SETFD, FD_CLOEXEC);
@@ -958,8 +961,3 @@ create_directory(const char *path, mode_t mode)
return B_OK; return B_OK;
} }
#ifdef USE_OPENBEOS_NAMESPACE
}; // namespace OpenBeOS
#endif