sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Should have seen this coming - Where to write temp files?

    Scheduled Pinned Locked Moved Developers' Forum
    24 Posts 7 Posters 606 Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      @thomthom said:

      @dan rathbun said:

      The method I point to is more elegant, and makes sure that the dir is writeable by the current user.

      But it requires webtextures to be enabled... which is not a guaranty.

      So copy it into "sketchup.rb" or into your own module.

      ENV vars can be changed... by another plugin.. by a user who doesn't know better.. whatever.

      Making an assumption that the path will be writable (without testing to be sure,) just sets you up for a future fall. And then you'll have to issue a update for your plugin, and waste a bunch of time placating angry customers.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        So here's what I've come up with. I did like Dan just suggested in the above post - I just copied their method and put it into my module I'm making. This is what I am using:

        
        tmp = ""
        for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], ENV['USERPROFILE'], '/tmp']
          if dir and File.directory?(dir) and File.writable?(dir)
            tmp = File.join( dir, 'temp_model')
            break
          end
        end
        @@temp_dir = File.expand_path(tmp)
        Dir.mkdir( @@temp_dir, 777 )
        
        

        It is working great on y PC, but the guy testing it on a Mac is getting permission denied errors. Any good reason he should be getting an error?

        Also, is there any way that the above script will ever not find a writable directory?

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @chris fullmer said:

          Also, is there any way that the above script will ever not find a writable directory?

          On Mac, if somebody wipes out the ENV['TEMPDIR'] value, AND the directory '/tmp' does not exist, then after the for loop, tmp would be empty.
          Make sure to add:
          ` if tmp.empty?

          make a tempTemp dir below HOME dir
          ie: delete the dir when done.

          end`

          ENV['USERPROFILE'] is Windows only.
          On Mac, it's ENV['HOME'].

          Myself.. I "hate" when programs write crap into my home dir.
          I'd prefer a "/temp" subdir if that was the only way to solve the issue.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            There's also a File.writable_real?(dir) method.
            Returns true if the named file is writable by the real user id of this process.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              What does the "real user" mean. I saw that in the docs but didn't understand the difference between the "effective user" and the "real user".

              Also, another thing I am doing in my script. I find their ENV[temp] directory as I showed in my example script. And then I write my own subdir called temp_model and then I try to write files to that subdir. When I make my subdir, I am giving it 777 permissions mkdir( mydir_string, 777 ). That should in theory be alloweable right? My subdir should have all the right permissions for me to write to it?

              Lately you've been tan, suspicious for the winter.
              All my Plugins I've written

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @unknownuser said:

                (http://en.wikipedia.org/wiki/Chmod)":1q6nz2xj]The chmod command accepts up to four digits to represent an octal number. The octets refer to bits applied to the file owner, group and other users, respectively. Use of three digits is discouraged because it leaves the fourth as the default and this value is not fixed.

                You can try: "777".oct
                see: String.oct

                also see: cacls for NT

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by

                  777 is a decimal number. 0o777 is an octal number. 0xDEADBEEF is a hexidecimal number. and 0b111111111 is a binary.

                  The file permission is a bit field - 3 sets of 3 bits.

                  If you want to set all 9 bits to 1, use 0o777 because:
                  0b111_111_111.to_s(8) 777

                  (You could just use 0b111111111 instead of 0o777, too)

                  Want to set just the owner to full rights, and deny eveyone else? Use 0700:
                  0b111000000.to_s(8) 700

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @chris fullmer said:

                    What does the "real user" mean. I saw that in the docs but didn't understand the difference between the "effective user" and the "real user".

                    see the setuid link (below)

                    @unknownuser said:

                    (http://en.wikipedia.org/wiki/Chmod#Special_modes)":2b9d9a8z]Special modes
                    The chmod command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use s to represent the setuid and setgid modes,

                    See also:

                    • File system permissions
                    • setgid
                    • setuid

                    Ruby methods:
                    File.setuid? File.setgid?

                    At the console:
                    "%b" % "777".oct

                    111111111
                    -> rwxrwxrwx

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @jim said:

                      777 is a decimal number. 0777 is an octal number. 0xDEADBEEF is a hexidecimal number. and 0b111111111 is a binary. Enter these in the Ruby Console to see.

                      I could not remember how to specify octals (which is why I went with the String method,) until you posted, reminding me of the " 0x" and " 0b" prefixes.

                      0o777

                      511

                      so:
                      "%b" % 0o777

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • P Offline
                        Pout
                        last edited by

                        i tend to do write temp content next to the Sketchup file and in the end just delete it again.
                        that location should be writable for sure.

                        1 Reply Last reply Reply Quote 0
                        • Chris FullmerC Offline
                          Chris Fullmer
                          last edited by

                          Yeah, I'm writing a LOT of files and they are persistant while the model is open. So I could have a few thousand files xluttering up someone's desktop 😄 hehhe. Might not go over well.

                          I still can't figure out why my Mac tester's computer won't let me write to his temp folder. It lets me create my folder, but then won't let me write to it.....grr. Oh yes, though come to think of it, he has not tested my new version using the different permission settings the Jim and Dan suggested. I better get him to try that soon.

                          Lately you've been tan, suspicious for the winter.
                          All my Plugins I've written

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            And you may have set the "special" bits, by accident, when you sent int(777) instead of int(511)...

                            .. I suggest having the tester, totally delete the folder manually, before trying the new version.

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • Chris FullmerC Offline
                              Chris Fullmer
                              last edited by

                              Ahh, good point.

                              Thanks so much everyone for all the help always. Its nice to be able to help people from time to and time, and even nicer when there are amazing people out there who are willing and able to help when needed. Very grateful, thanks Dan (et al)

                              Chris

                              Lately you've been tan, suspicious for the winter.
                              All my Plugins I've written

                              1 Reply Last reply Reply Quote 0
                              • Dan RathbunD Offline
                                Dan Rathbun
                                last edited by

                                Just noticed ANOTHER standard Ruby extension that bears on this subject.

                                With a path to the local standard Ruby lib dir pushed into the $LOAD_PATH array, you add the following to your module:
                                require('tmpdir.rb')

                                This standard extension adds the class methods:
                                Dir::tmpdir and Dir::mktmpdir

                                If you read the file, you'll recognize the Dir::tmpdir method as the 'progenitor' of the edition in the Google 'webtextures_loader.rb' file. (Google "lifted" it, and stripped out the Win32 specific part.)

                                So (above) when we talked about whether to rely on the WebTextures plugin, my advice is, to instead rely on the Standard Ruby library.

                                I'm not here much anymore.

                                1 Reply Last reply Reply Quote 0
                                • 1
                                • 2
                                • 1 / 2
                                • First post
                                  Last post
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement