Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.1 KiB

  1. /*
  2. * D I R I T E R . C P P
  3. *
  4. * Sources for directory ineration object
  5. *
  6. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  7. */
  8. #include "_davfs.h"
  9. DEC_CONST WCHAR gc_wszGlobbing[] = L"**";
  10. DEC_CONST UINT gc_cchwszGlobbing = CElems(gc_wszGlobbing) - 1;
  11. // CDirState -----------------------------------------------------------------
  12. //
  13. SCODE
  14. CDirState::ScFindNext (void)
  15. {
  16. SCODE sc = S_OK;
  17. // If the find has not yet been established, then
  18. // do so here
  19. //
  20. if (m_hFind == INVALID_HANDLE_VALUE)
  21. {
  22. // Establish the find handle
  23. //
  24. m_rpPathSrc.Extend (gc_wszGlobbing, gc_cchwszGlobbing, FALSE);
  25. if (FALSE == DavFindFirstFile(m_rpPathSrc.PszPath(), &m_hFind, &m_fd))
  26. {
  27. sc = HRESULT_FROM_WIN32(GetLastError());
  28. goto ret;
  29. }
  30. }
  31. else
  32. {
  33. // Just find the next file
  34. //
  35. if (!FindNextFileW (m_hFind, &m_fd))
  36. {
  37. sc = S_FALSE;
  38. goto ret;
  39. }
  40. }
  41. // Extend the resource paths with the new values
  42. //
  43. Extend (m_fd);
  44. ret:
  45. return sc;
  46. }
  47. // CDirIter ------------------------------------------------------------------
  48. //
  49. SCODE
  50. CDirIter::ScGetNext(
  51. /* [in] */ BOOL fSubDirectoryAccess,
  52. /* [in] */ LPCWSTR pwszNewDestinationPath,
  53. /* [in] */ CVRoot* pvrDestinationTranslation)
  54. {
  55. SCODE sc = S_OK;
  56. // If the current item is a directory, and we intend to
  57. // do subdirectory iteration, then go ahead and try and
  58. // push our context down to the child directory
  59. //
  60. if (m_fSubDirectoryIteration &&
  61. fSubDirectoryAccess &&
  62. FDirectory() &&
  63. !FSpecial())
  64. {
  65. // Add a reference to the current directory state
  66. // and push it onto the stack
  67. //
  68. m_pds->AddRef();
  69. m_stack.push_back (m_pds.get());
  70. // Replace the current directory state with the new one
  71. //
  72. m_pds = new CDirState (m_sbUriSrc,
  73. m_sbPathSrc,
  74. m_sbUriDst,
  75. pwszNewDestinationPath
  76. ? pwszNewDestinationPath
  77. : m_pds->PwszDestination(),
  78. pvrDestinationTranslation
  79. ? pvrDestinationTranslation
  80. : m_pds->PvrDestination(),
  81. m_fd);
  82. }
  83. // Find the next file in the current context
  84. //
  85. sc = m_pds->ScFindNext();
  86. // If S_FALSE was returned, then there were no more
  87. // resources to process within the current context.
  88. // Pop the previous context off the stack and use it
  89. //
  90. while ((S_OK != sc) && !m_stack.empty())
  91. {
  92. // Get a reference to the topmost context on the
  93. // stack and pop it off
  94. //
  95. m_pds = const_cast<CDirState*>(m_stack.back());
  96. m_stack.pop_back();
  97. // Release the reference held by the stack
  98. //
  99. m_pds->Release();
  100. // Clear and/or reset the find data
  101. //
  102. memset (&m_fd, 0, sizeof(WIN32_FIND_DATAW));
  103. // See if this context had anything left
  104. //
  105. sc = m_pds->ScFindNext();
  106. }
  107. // If we have completely exhausted the files to process
  108. // or encountered another error, make sure that we are
  109. // not holding onto anything still!
  110. //
  111. if (sc != S_OK)
  112. {
  113. // This should perform the last release of anything
  114. // we still have open.
  115. //
  116. m_pds.clear();
  117. }
  118. return sc;
  119. }