https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112012-11-24T10:45:36ZRuby Issue Tracking SystemRuby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=337192012-11-24T10:45:36Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>akr (Akira Tanaka)</i></li><li><strong>Target version</strong> set to <i>2.6</i></li></ul> Ruby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=511852015-01-22T14:39:14ZSalzig (Ben Rexin)ben@rexin.at
<ul></ul><p>Any way i can help?</p> Ruby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=512072015-01-24T21:20:44Zdjberg96 (Daniel Berger)
<ul></ul><p>I'm a little surprise there isn't an option for this in <code>FileUtils</code>. Something like <code>FileUtils.touch('/location/for/new', :force => true)</code>. I'd be in favor of adding that, or an option to <code>FileUtils.mkpath</code>.</p> Ruby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=579742016-04-07T15:35:22Zdsisnero (Dominic Sisneros)dsisnero@gmail.com
<ul></ul><p>Any update on this</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Pathname</span>
<span class="k">def</span> <span class="nf">touch</span><span class="p">(</span><span class="n">options</span><span class="o">=</span><span class="p">{})</span>
<span class="no">FileUtils</span><span class="p">.</span><span class="nf">touch</span><span class="p">(</span><span class="vi">@path</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="no">Pathname</span><span class="p">(</span><span class="s1">'test.pdf'</span><span class="p">).</span><span class="nf">touch</span><span class="p">(</span><span class="ss">mtime: </span><span class="mi">1</span><span class="p">.</span><span class="nf">hour</span><span class="p">.</span><span class="nf">ago</span><span class="p">)</span>
</code></pre>
<p>"#mkpath" almost works but doesn't have the mtime option</p> Ruby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=580512016-04-13T06:50:10Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>I don't like the method name "touch".</p>
<p>"touch" command has multiple features:<br>
create empty file, update mtime.<br>
So, the intent of touch method is ambiguous.</p> Ruby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=596962016-07-19T19:25:04Znajamelan (Naja Melan)
<ul></ul><p>I prefer something like (warning, untested code):</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">touch</span><span class="p">(</span> <span class="n">subPath</span> <span class="o">=</span> <span class="s1">''</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span> <span class="p">)</span>
<span class="n">path</span> <span class="o">=</span> <span class="vi">@path</span>
<span class="n">ret</span> <span class="o">=</span> <span class="nb">self</span>
<span class="k">if</span> <span class="n">directory?</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">join</span> <span class="n">subPath</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">ret</span><span class="p">.</span><span class="nf">to_path</span>
<span class="k">end</span>
<span class="no">FileUtils</span><span class="p">.</span><span class="nf">touch</span><span class="p">(</span> <span class="n">path</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span> <span class="p">)</span>
<span class="n">ret</span>
<span class="k">end</span>
</code></pre>
<p>lets you do:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">mydir</span><span class="p">.</span><span class="nf">touch</span> <span class="s1">'somefile'</span>
</code></pre>
<p>I think touch is a good name because everybody already knows it and it's what people will try out spontaneously before even looking in the docs why it doesn't work. Joel Spolsky <a href="http://www.joelonsoftware.com/uibook/fog0000000249.html" class="external">explains quite well</a> why this is a good thing.</p> Ruby master - Feature #7361: Adding Pathname#touchhttps://redmine.ruby-lang.org/issues/7361?journal_id=596982016-07-20T00:32:16Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>We don't always blindly import broken designs; for instance Ruby do not have creat(2) equivalent method. "Everybody knows it" is (definitely a good property but) not enough.</p>
<p>When it comes to touch, there already is <code>FileUtils.touch</code> so your urgent needs are already satisfied I believe. Here on <code>Pathname</code> let us consider a clearer design.</p>