bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: NSPathUtilities etc


From: Adam Fedor
Subject: Re: PATCH: NSPathUtilities etc
Date: Tue, 2 Mar 2004 21:39:58 -0700

Some more comments on NSPathUtilities.m. I think I'd be ready to commit this after addressing these comments.

/* Initialise all things required by this module */
void InitialisePathUtilities(void)
{
  NSDictionary  *env;
  NSDictionary  *dict = nil;

  /* Set up our root paths */
  NS_DURING
    {
      /* Initialise Win32 things if on that platform */
      Win32Initialise();   // should be called by DLL_PROCESS_ATTACH

      [gnustep_global_lock lock];

      /* Set the file manager */
      if (file_mgr == nil)
        set_file_mgr();

      /* First we look at the environment */
      env = [[NSProcessInfo processInfo] environment];

test_assign(gnustep_system_root , [env objectForKey: SYSTEM_ROOT]); test_assign(gnustep_network_root, [env objectForKey: NETWORK_ROOT]); test_assign(gnustep_local_root , [env objectForKey: LOCAL_ROOT]);

#if defined(__WIN32__)
//    {
//      HKEY regkey;
//
//      regkey = Win32OpenRegistry(HKEY_LOCAL_MACHINE,
//                 "\\Software\\GNU\\GNUstep");
//      if (regkey != nil)
//        {
//          test_assign(gnustep_system_root,
//                  Win32NSStringFromRegistry(regkey, SYSTEM_ROOT));
//          test_assign(gnustep_network_root,
//                  Win32NSStringFromRegistry(regkey, NETWORK_ROOT));
//          test_assign(gnustep_local_root,
//                  Win32NSStringFromRegistry(regkey, LOCAL_ROOT));
//          RegCloseKey(regkey);
//        }
//
//      platform_apps   = Win32FindDirectory(CLSID_APPS);
//      platform_libs   = Win32FindDirectory(CLSID_LIBS);
//    }
#endif

      /* Now we source the configuration file */
      dict = GSReadStepConfFile( GNUSTEP_CONFIGURATION_FILE );
      if (dict != nil)
        {
test_assign(gnustep_system_root , [dict objectForKey: SYSTEM_ROOT]); test_assign(gnustep_network_root, [dict objectForKey: NETWORK_ROOT]); test_assign(gnustep_local_root , [dict objectForKey: LOCAL_ROOT]);

gnustep_rc_filename = [dict objectForKey: @"USER_GNUSTEP_RC"]; gnustep_defaultspath = [dict objectForKey: @"USER_GNUSTEP_DEFAULTS"];
          gnustep_userpath = [dict objectForKey: @"USER_GNUSTEP_DIR"];

#ifdef PLATFORM_SUPPORT
          os_sys_prefs = get_pathconfig(dict, SYS_PREFS);
          os_sys_apps  = get_pathconfig(dict, SYS_APPS );
          os_sys_libs  = get_pathconfig(dict, SYS_LIBS );
          os_sys_admin = get_pathconfig(dict, SYS_ADMIN);

platform_resources = get_pathconfig(dict, PLATFORM_RESOURCES);
          platform_apps      = get_pathconfig(dict, PLATFORM_APPS );
          platform_libs      = get_pathconfig(dict, PLATFORM_LIBS );
          platform_admin     = get_pathconfig(dict, PLATFORM_ADMIN);

local_resources = get_pathconfig(dict, PLATFORM_LOCAL_RESOURCES);
          local_apps      = get_pathconfig(dict, PLATFORM_LOCAL_APPS);
          local_libs      = get_pathconfig(dict, PLATFORM_LOCAL_LIBS);
#endif // PLATFORM SUPPORT

          [dict release];
        }

      test_assign( gnustep_rc_filename,  DEFAULT_STEPRC_FILE);
      test_assign( gnustep_defaultspath, DEFAULT_DEFAULTS_PATH);
      test_assign( gnustep_userpath, DEFAULT_USER_ROOT);

      /* If the user has an rc file we need to source it */
      set_user_gnustep_path();
I'd like to keep support for the root .GNUsteprc file as well, at least until we decide to depreciate it.

      /* Make sure that they're in path internal format */
      internalise_path(gnustep_system_root);
      internalise_path(gnustep_network_root);
      internalise_path(gnustep_local_root);
      internalise_path(gnustep_user_root);

//  NSLog(@"System root is '%@'\n",gnustep_system_root);
//  NSLog(@"Network root is '%@'\n",gnustep_network_root);
//  NSLog(@"Local root is '%@'\n",gnustep_local_root);
//  NSLog(@"User root is '%@'\n",gnustep_user_root);

      /* Finally we check and report problems... */
      if (gnustep_system_root == nil)
        {
          gnustep_system_root = internalise_path_Cstring( \
                                  stringify(GNUSTEP_INSTALL_PREFIX));
fprintf (stderr, "Warning - GNUSTEP_SYSTEM_ROOT is not set " \ "- using %s\n", [gnustep_system_root lossyCString]);
        }

Also, I think we should set GNUSTEP_LOCAL_ROOT and GNUSTEP_NETWORK_ROOT from the compiled in values if they are not found anywhere as well (as is done currently.)

With those changes, people's current setups will work correctly without any changes.


/**
 * Returns loginName's home directory as an NSString object.
 */
/* NOTE FOR DEVELOPERS.
 * If you change the behavior of this method you must also change
 * user_home.c in the makefiles package to match.
 */
NSString *
NSHomeDirectoryForUser(NSString *loginName)
{
#if defined(__WIN32__)
  NSString      *s = nil;

  s = Win32GetUserProfileDirectory(loginName);
  return internalise_path(s);
Does this look at HOMEPATH or USERPROFILE? Should we allow the user to override this with HOMEPATH, etc, if not?


/**
* Returns the name of a directory in which temporary files can be stored.<br/ >
 * For unix-like systems this is usually '/tmp'.<br/ >
* For MS-Windows systems this is the system temporary directory, often '%WINDIR%\TEMP\'.<br/ >
 */
NSString
*NSTemporaryDirectory(void)
{
  NSString      *tempDirName = nil;
  BOOL          flag;
  NSDictionary  *env;

  /*
   * If the user has supplied a directory name in the TEMP or TMP
   * environment variable we use that.
   */
  env = [[NSProcessInfo processInfo] environment];

  tempDirName = [env objectForKey: @"TEMP"];
  if (tempDirName == nil)
    {
      tempDirName = [env objectForKey: @"TMP"];
    }

  /*
   * Windows has a specific function call to find temp
   */
#if defined(__WIN32__)
  if (tempDirName == nil)
    {
      char buffer[MAX_PATH];

      if (GetTempPath(MAX_PATH, buffer))
        {
          tempDirName = internalise_path_Cstring(buffer);
        }
    }
#endif

  /*
   * Fallback to unix standards otherwise.
   */
  if (tempDirName == nil)
    {
      tempDirName = @"/tmp";  // standard unix FHS place
    }

  /*
   * Check that the directory exists ... if it doesn't we can't
   * go any further.
   */
  if ([file_mgr fileExistsAtPath: tempDirName isDirectory: &flag] == NO
    || flag == NO)
    {
NSLog(@"Temporary directory (%@) does not seem to exist", tempDirName);
      return nil;
    }

  /*
   * Check that the directory is writable
   */
  if ([file_mgr isWritableFileAtPath: tempDirName] == NO)
    {
      NSLog(@"Temporary directory (%@) is not writable", tempDirName);
      return nil;
    }
Why did you take out the creation of a secure subdirectory of temp?

  return tempDirName;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]