Skip to content

Trailing slash consistency between __dirname and os.tmpdir() #715

Description

@hacksparrow
console.log(os.tmpdir()) // trailing slash
console.log(__dirname) // no trailing slash

Is there a good reason why os.tmpdir() ends with a trailing slash, while __dirname does not? If there is none, it might make sense to make the return values consistent.

Activity

  1. micnic commented on Feb 4, 2015

    @micnic
    Contributor

    it may be that this is a platform specific issue, for me they are both without trailing slash, what operating system are you using?

  2. cjihrig commented on Feb 4, 2015

    @cjihrig
    Contributor

    os.tmpdir() comes directly from environment variables. __dirname uses path.dirname(), which strips trailing slashes.

  3. hacksparrow commented on Feb 4, 2015

    @hacksparrow
    Author

    Mac OS.

  4. tellnes commented on Feb 4, 2015

    @tellnes
    Contributor

    Maybe we should make os.tmpdir() strip trailing slashes?

  5. cjihrig commented on Feb 4, 2015

    @cjihrig
    Contributor

    It would be nice to be consistent, but it could potentially break existing code.

  6. tellnes commented on Feb 4, 2015

    @tellnes
    Contributor

    Yes it will probably break some existing code, but I still see this as a bug.

  7. cjihrig commented on Feb 4, 2015

    @cjihrig
    Contributor

    I would be OK with this for a major version bump, but I'd like to hear what others think.

  8. added
    osIssues and PRs related to the os subsystem.
    on Feb 5, 2015
  9. hacksparrow commented on Feb 6, 2015

    @hacksparrow
    Author

    Right now I am getting through by adding a mandatory '/' everywhere I suspect the slash may or may not be found, and using path.normalize(). But it is an inelegant solution.

    Probably iojs should work on normalizing the trailing slash to provide for a consistent interface. It is a pain when something works on Mac and fails on Linux, and vice versa.

  10. micnic commented on Feb 6, 2015

    @micnic
    Contributor

    I was looking on Github for modules which use os.tmpdir() and most of them use path methods to deal with it, only about 4 modules out of ~50 that I found were using raw string concatenation which can lead to some issues

  11. tellnes commented on Feb 6, 2015

    @tellnes
    Contributor

    This is a quick fix in io.js and a quick fix in those modules if they break. I'll go ahead and create a pull request and then the only thing left is to choose whether to merge or not.

  12. tellnes commented on Mar 22, 2015

    @tellnes
    Contributor

    Landed in next branch as bb97b70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    osIssues and PRs related to the os subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions